1
私は数百万のレコードを持つファイルを持っています。ここで私は2000年の最初のレコードを読んで、それを削除してから削除したいと思う。 レコードを読み取ることはできますが、削除方法を教えてください。最初にテキストファイルから1000行を削除します
public class Files {
public static void files(int index) throws IOException {
try {
//numbers num = new numbers();
BufferedReader br = null;
BufferedWriter bw = null;
try {
String sCurrentLine = "";
br = new BufferedReader(new FileReader("data.txt"));
bw = new BufferedWriter(new FileWriter("File_2.txt"));
int i = 0;
while ((sCurrentLine = br.readLine()) != null && i < index) {
System.out.println(++i + " " + sCurrentLine);
bw.write(sCurrentLine);
bw.write(System.getProperty("line.separator"));
//sCurrentLine = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
bw.close();
if (br != null) {
br.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
} catch (Exception e) {
}
}
}
コードを正しくフォーマットしてください。 – Dakkaron
可能な複製http://stackoverflow.com/questions/1377279/find-a-line-in-a-file-and-remove-it –
とbtwは表示されませんあなたはどこにでもiを増やします。 –