In the following program, loop is iterating 1000 times, and I am writing all the entries in a file using a FileWriter, but unfortunately programs ends up writing only 510(sometimes 415, sometimes 692, always less then 1000) entries in the file, but loop is iterating 1000 times.
import java.io.* ;
import java.util.*;
public class DemoWriter {
public static void main(String[] args) throws Exception {
List<String> receiverList = new ArrayList<String>() ;
receiverList.add("[email protected]") ;
receiverList.add("[email protected]") ;
receiverList.add("[email protected]") ;
FileWriter fw = new FileWriter("a.txt") ;
BufferedWriter bw = new BufferedWriter(fw) ;
int size = receiverList.size() ;
String str ;
int count = 0 ;
for(int i = 1 ; i <= 1000 ; ++i){
str = receiverList.get( (int) (Math.random() * size) ) + "\n" ;
bw.write(++count + ".> " + str) ;
System.out.print(count + ".> " + str) ;
}
}
}
Is this because of file size or something else???
Thnx for the quick response to all the nice people here. I have corrected my code (I just forgot to close the stream and now code working perfectly). As all pointed that i need to close the stream, but i am accepting BalusC as he was the first one who replied.
Nice to c u BalusC here. Cheers :)