Bir dosyamda milyonlarca kayıt var. Burada ilk 2000 kayıtlarını okumak ve okuduktan sonra silmek istiyorum. Kayıtları okuyabiliyorum ama lütfen nasıl sileceğimi bildirin.Metin dosyasından ilk 1000 satırı sil
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) {
}
}
}
Lütfen kodunuzu doğru şekilde biçimlendirin – Dakkaron
http://stackoverflow.com/questions/1377279/find-a-line-in-a-file-and-remove-it –
ve btw'nin olası kopyası Her yerde seni arttırırsın. –