Can any one please correct this code. This is to read a file and later it should write the output to a file. Input file has 20 rows and 4 columns. If we have 1 in the 1st column of the input file then it should count all 1's and write those 1s counted value to a file.
Code:
import java.io.*;
import java.util.*;
import java.lang.ClassNotFoundException;
class Code
{
public static void main(String[] args) throws IOException
{
String str[][] = new String[20][4];
FileReader fr = new FileReader("in.txt");
BufferedReader br = new BufferedReader( fr );
FileWriter fw = new FileWriter("out.txt");
PrintWriter pw = new PrintWriter(fw);
String line = "";
int i = 0, j= 0, one=0, two=0,three=0;
while( ( line = br.readLine() ) != null )
{
StringTokenizer tok = new StringTokenizer(line, ", ");
if(str[i][0].equals("1") )
{
one = one++;
}
else if(str[i][0].equals("2") )
{
two = two++;
}
else if(str[i][0].equals("3") )
{
three = three++;
}
i++;
}
br.close();
fr.close();
System.out.println("Sending the output to file:");
for(i=0;i < 20; i++)
{
for(j=0;j<4; j++)
{
System.out.printf("one" +one);
pw.print(one);
System.out.println("two" +two);
pw.print(two);
System.out.println("three" +three);
pw.print(three);
}
pw.println();
}
pw.close();
fw.close();
}
}