hi all,
I'm using Java input /out files
I'm reading from a txt file which holds intger
and I would like to sum them and put the result in a new txt file holds the output as an integer but it holds un-understandable thing such as ( )
this is the source code , it's compiled,
Waiting for your respone..
I'm using Java input /out files
I'm reading from a txt file which holds intger
and I would like to sum them and put the result in a new txt file holds the output as an integer but it holds un-understandable thing such as ( )
this is the source code , it's compiled,
Code:
package filetest2;
import java.util.Scanner;
import java.io.*;
class fileTest2 {
public static void main(String [] args) throws Exception{
FileInputStream a1 = new FileInputStream("input.txt") ;
DataInputStream a2 = new DataInputStream(a1) ;
FileOutputStream a3 = new FileOutputStream("out.txt");
DataOutputStream a4 = new DataOutputStream(a3);
Scanner scan = new Scanner (a1);
int sum1 = 0;
int numOfLines = scan.nextInt();
for (int i= numOfLines;i>0;i--)
{ int numOfTests = scan.nextInt();
for (int j = numOfTests;j>0;j--)
sum1 =+ scan.nextInt();
}
a4.write(sum1);
a3.close();
a1.close();
}
}
Comment