Nook Interview Question
Senior Software Development EngineersCountry: United States
Interview Type: In-Person
out
in
System
is the output stream of a java process, you can redirect it to a file with redirection operator
java ClassName >/file/you/want/to/save/to
If you want to redirect the error stream to a file, use
java ClassName 2>/file/you/want/to/save/to
For any CLI process there are at least 3 streams associated with it,
stdin 0
stdout 1
stderr 2
0,1,2 are the file descriptor of the respective streams
Yes, you can create your own PrintStream and set it as the output stream of your program
package com.test;
import java.io.FileNotFoundException;
import java.io.PrintStream;
public class Test {
public static void main(String[] args) throws FileNotFoundException {
System.setOut(new PrintStream("outfile.txt"));
System.out.println("Hello, World!");
}
}
Actually out is a static member in the System class , being an instance of PrintStream. And println is a normal (overloaded) method of the PrintStream class...
- saxenasaral September 09, 2014