BufferedWriter skipping last 10 lines
900707Oct 12 2012 — edited Oct 12 2012Hello Experts,
I have developed one program which is reading line by line from a file and replacing comma with null.
sample file1
alex|,20|,uk|,255555|,
...............
...............
after replace and writing to a new file
alex|20|uk|255555|
.............
.............
The problem is that though it is replacing properly but at the end i can see few lines are missing in the new file. I am not sure whats the reason. I guess it related out of memory problem but i am not getting any error. Here is my code. My files contains around 20,000 lines.
String curdate=new SimpleDateFormat("yyyyMMdd").format(Calendar.getInstance().getTime()).toString();
String filename= "D:/FF/1CIM_20121012.txt";
try
{
FileReader fr = new FileReader(filename);
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter("D:/FF/123CIM_20121012.txt");
BufferedWriter bw = new BufferedWriter(fw);
String line = null;
while((line=br.readLine()) != null) {
line= line.replaceAll(",","");
bw.write(line);
bw.newLine();
}
fr.close();br.close();fw.close();bw.close();
}
catch(IOException ioe)
{
System.err.println("IOException: " + ioe.getMessage());
}
Please suggest.