Hello. I am learning java and tried to make a simple program, which reads the int number and writes it into a file. The problem is - the txt file remains empty. Take a look at the code:
import java.io.*; import java.util.*; class Job { int x; public int inputTxt() { try { x = System.in.read(); } catch (Exception e) { System.out.println("input error"); } return x; } public void outputF() { try { OutputStream f = new FileOutputStream("test.txt"); f.write(x); } catch (Exception e) { System.out.println("output error"); } } public void closeF() { try { OutputStream f = new FileOutputStream("test.txt"); f.close(); } catch (Exception e) { System.out.println("close error"); } } } class Test { public static void main(String args [ ]) { Job j = new Job(); j.inputTxt(); j.outputF(); j.closeF(); } }