I have a file have lot of records in millions. here I want to read first 2000 records and delete them after read. i am able to read record but please let me know how to delete.
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) {
}
}
}