Computer Science Canada [Tutorial] Read / Write to Terminal |
Author: | rizzix [ Mon Jun 02, 2003 6:14 pm ] | ||||
Post subject: | [Tutorial] Read / Write to Terminal | ||||
To get input from Terminal. import all classes from the java.io package. (we will be using only 3 of the imported classes though)
then the rest is as follows:
Here we declared 2 refrences of type: BufferedReader and PrintStream. The BufferedReader refrence is used to refer to an object of type BufferedReader, which has methods that can be used to read lines of text from anywhere. In this case System.in. The BufferedReader object takes an InputStreamReader object as its arguemens for its Constructor. Which in turn initializes its self with an InputStream object. The System.in object is of type InputStream. Thus we create new instances of the necessary objects passing them the appropriate objects as arguments, finally creating the BufferedReader object to use. There is also a public int read() method for the BufferedReader objects to read a single character at a time. We used the out reference to refer to the System.out object. |
Author: | DanShadow [ Wed Oct 20, 2004 7:44 pm ] |
Post subject: | |
Ok, so that works with reading from a file. But could you explain how to write to a file? tx |
Author: | zylum [ Thu Oct 21, 2004 6:10 pm ] |
Post subject: | |
that only explains reading keyboard input |
Author: | wtd [ Thu Oct 21, 2004 6:16 pm ] | ||
Post subject: | |||
I think...
Manipulate it the same way you would console I/O. |
Author: | Hikaru79 [ Mon Aug 01, 2005 12:27 pm ] | ||
Post subject: | |||
DanShadow wrote: Ok, so that works with reading from a file. But could you explain how to write to a file? tx
As for File Output:
|