Java I/O Query

Revision en1, by Sibin_Thomas, 2020-09-21 16:45:35

I wanted to take input from a file and print output to another file. I am able to take the input successfully(Tested using System.out) but there is no output on the output file.

import java.util.*;
import java.io.*;

class a{

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	public a() throws Exception{
		if (System.getProperty("ONLINE_JUDGE") == null) {
			br = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(new FileWriter("output.txt"));
		}
		else {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		}
	}

	public void solve() throws IOException{
		int n = Integer.parseInt(br.readLine());
		out.println(n);
		out.flush();
	}

	public static void main(String[] args) throws Exception{
		new a().solve();
	}
}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Sibin_Thomas 2020-09-21 16:45:35 871 Initial revision (published)