Is it possible to reopen standard Console I/O streams during execution after closing them?
public static void main(String[] args) throws IOException {
System.out.println("Hello World!!!");
System.out.println("1:" + System.in.read());
System.out.println("" + FileDescriptor.in.valid()); //true
System.in.close();
System.out.println("" + FileDescriptor.in.valid()); //false
System.out.println("2:" + System.in.read()); //IOException
System.in.close();
}
From this post I could figure out that private static native void setIn0(InputStream in);
native function is used to initialize final I/O streams in private static void initializeSystemClass()
private method after thread initialization.
Can I renitialize the I/O streams?
Edit:
As System.in
is a final
object I cannot modify it with things like
System.in=new InputStream() {
@Override
public int read() throws IOException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
during runtime...
What I am expecting is a solution through Native Methods/Function to retrieve the Console' handle