April 22
Examples from April 22
Today we worked with files and streams:
Copy.java This gets the names of source and destination files from command line arguments. . The buffered read and buffered write abilities of FileReader and FileWriter are used to copy the source into the destination with just two instructions and no loops. For example, to copy the file "Copy.java" into file "CopyOfCopy" you would use the command java Copy Copy.java CopyOfCopy.
FileStream.java and SimpleInput.java This uses SimpleInput to read strings of text. The stream classes are used to put these strings into a text file, and then to read and print the file.
SystemStream.java This uses streams to read strings of text from the user; these strings are added to an array, which at the end is printed out. Note that this makes no use of the SimpleInput class. This is the first example we have done of reading text from the keyboard using native java methods.