日期:2014-05-20 浏览次数:20821 次
文本开始
文本0
--##begin
要删除的文本
要删除的文本
--##end
文本1
文本结束
InputStreamReader read = null;
try {
FileWriter fw = new FileWriter("输出文件路径");
read = new InputStreamReader(new FileInputStream(new File("输入文件路径")));
BufferedReader br = new BufferedReader(read);
String line = br.readLine();
boolean deleted = false;
while (line != null) {
if (line.trim().equals("--##begin")) {
deleted = true;
fw.write("--##begin\r\n");
} else if (line.trim().equals("--##end")) {
deleted = false;
fw.write("要插入的内容\r\n");
fw.write("--##end\r\n");
} else if (!deleted) {
fw.write(line + "\r\n");
}
line = br.readLine();
}
br.close();
read.close();
fw.close();
} catch (IOException ex) {
ex.printStackTrace(System.err);
}