java 删除关键字所在行

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;


public class Text
{
	public static void main(String[] args) throws Exception
	{
		File file = new File("d:/11.txt");
		String rl = null;
		String special = "小红";
		StringBuffer bf = new StringBuffer();
		BufferedReader br = new BufferedReader(new FileReader(file));
		while(( rl = br.readLine()) != null)
		{
			rl = rl.trim();
			if(rl.indexOf(special) == -1){ //或者!r1.startsWith(special)
				bf.append(rl).append("\r\n");
			}
		}
		br.close();
		
		BufferedWriter out = new BufferedWriter(new FileWriter(file));
		out.write(bf.toString());
		out.flush();
		out.close();
	}
}

你可能感兴趣的:(java 删除关键字所在行)