I'm trying to read from a file, take the length of the each line, write the length into another file and then print the second file to see the writing result, but when I open the second file the result is not exactly the thing that I want. There are many numbers in the file after running this code:
String line = null;
boolean flag = false;
BufferedReader bf = new BufferedReader(new FileReader("c:\\lm_giga_5k_nvp_2gram.arpa"));
BufferedWriter index = new BufferedWriter(new FileWriter("c:\\index.txt"));
int l;
int counter=0;
while (( line = bf.readLine()) != null)
{
l=line.length();
index.write( l + "\n" );
}
BufferedReader bf1 = new BufferedReader(new FileReader("c:\\index.txt"));
String line1=null;
while (( line1 = bf1.readLine()) != null)
{
System.out.println(line1);
}
bf.close();
bf1.close();
Please help me using this example. I close the index, but still have the same problem.
Notice: Don't pay attention to arpa file you can image a txt file instead.