【发布时间】:2012-02-08 22:33:50
【问题描述】:
我有一个正在阅读的文本文件。它有我想要删除的块。有没有办法我可以说如果读者遇到一个字符串“帐户声明”,它会跳过阅读该语句之前的 10 行。这是我目前使用的代码,它从文本文件中读取所有内容。
for(int i = 0; i < filenames.length; i++){
FileInputStream fstemp = new FileInputStream("C:/Temporary/" + filenames[i]);
FileOutputStream fos = new FileOutputStream("C:/Statements/" + filenames[i]);
DataInputStream in1 = new DataInputStream(fstemp);
UniqueLineReader brtemp = new UniqueLineReader(new InputStreamReader(in1));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
String strLine;
while((strLine = brtemp.readLine()) != null){
bw.write(strLine);
bw.newLine();
bw.flush();
}
}
【问题讨论】:
-
如果正在读取一个文件,如果它是顺序读取,它如何跳过之前它刚刚读取的行?
-
我假设您的意思是“之后”而不是“之前”您的关键字。为什么不直接保存这 10 行的数据?
-
如果有人回答了您的问题,请采纳。
标签: java