Hello!!!
mmm am learning OOP in Java ... and now I'm facing a prob in reading/writing .txt file
here's my code:
import java.util.Scanner;
import java.util.Formatter;
import java.io.File;
import java.io.FileNotFoundException;
public class Tester {
public static void main(String[] args)
{
Scanner scan = null;
Formatter formatter = null;
File fileI;
File fileO;
fileI = new File("/home/amir/workspace/ForExam1/src/Class1/input.txt");
fileO = new File("/home/amir/workspace/ForExam1/src/Class1/output.txt");
try {
scan = new Scanner(fileI);
formatter = new Formatter(fileO);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int first = scan.nextInt();
formatter.format("%d", first);
}
}
and here the input.txt file:
123
The code is generating the "output.txt" file put it's empty, I SOP the 'first' variable which has the value of '123' and it worked ... but the code is not writing the value of 'first' in the output.txt ...
Anyidea how to fix this code??.
Thank you, Regards