Currently its impossible to restore the standard io streams if they have been closed. One needs the flexibility to temporarily close the standard io and make System.in (out and err) use different streams and then restore the standard io streams.
This can be achieved by duplicating FileDescriptors, i.e have the ability to create an additional entry in the File descriptor table pointing to the same file. Thus even if one of the file descriptors is freed one can still use the duplicate fd to reestablish a file stream.
The FileDescriptors System.in(out and err) are set to -1, if the FileStream using them is closed, rendering them useless. There is no other portable way of dealing with stdio other than using file descriptors.
Assuming FileDescriptor.dup() exists, the code could look like,
....
FileDescriptor backupStdin = FileDescriptor.in.dup();
System.in.close();
// Set a different stream (file) to be used as stdin
System.setIn(....)
... Do Stuff using System.in ....
// Restore Stdin using backed up fd.
System.setIn(new BufferedInputStream(new FileInputStream(backupStdin));
... Now use regular Stdin, with System.in
naveen.sanjeeva@eng 1999-09-22