Sibin_Thomas's blog

By Sibin_Thomas, history, 4 years ago, In English

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();
	}
}
  • Vote: I like it
  • 0
  • Vote: I do not like it