Testing a Java program

I had developed my solution to work as “java Main in.txt out.txt”, however I am receiving a “Wrong answer” message when a submit my solution.

In the FAQ I have found that I must test using java test < in.txt > out.txt, but I do not understand what is the purpose of “<” and “>”.
The FAQ says that “…< and > to redirect the streams” but that do not makes much sense, my Java program takes “<” and “>” as arguments as well.

Besides, in the Wiki, there is a sample for Java solutions:

java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));

String s;

while (!(s=r.readLine()).startsWith(“42”)) System.out.println(s);

And I do not see that they use the input parameter “< in.txt >” anywhere.


I have figured out what the problem was: when executing, from the console (I was executing my application from Netbeans), the code “java test < in.txt > out.txt”, the string “< in.txt > out.txt” is not passed has parameters to the Java main method. Instead:

  • "< in.txt" indicates to the Java Virtual Machine that every time that the stream “System.in” is read, the information is going to come from the file “in.txt”.
  • "> out.txt" indicates that every time that “System.out” is used (for example when calling “System.out.println(56)”) the information must be saved into the file “out.txt”, instead of being displayed into the console (which is the default behaviour).

As consequence, the Java’s sample application ( http://www.codechef.com/wiki/sample-solutions#Java ) what does is to copy all the content of “in.txt” into “out.txt”.

1 Like