CSC 120

Week 12


Reading Assignment:

Read Sections 7.1-2, 10.1-3

Code Examples:

Here are some of the programs we examined in class, and more:
Person.java
Student.java
Kid.java
StudentTest.java
StudentTest1.java
StudentTest2.java
FileWrite.java
FileReadScanner.java
FileReadScanner2.java
FileReadScanner3.java
WordCount.java
poem.txt
hello.txt
FileReadWriteScanner.java
numbers.txt
LS.java


Programming Assignments:

  1. Write a program named MyCat.java that appends text file file2.txt to the end of another text file file1.txt and outputs the result in a third text file file3.txt. Do not assume the knowledge of the number of lines in the files. Create two short text files named file1.txt and file2.txt and test your program.

    Hint: modify the code in FileReadWriteScanner.java above.

    This program MyCat is equivalent to the Unix command

    cat file1.txt file2.txt > file3.txt

    Type (in the lab computer)
    man cat
    to read about the manual pages on cat. Try cat with your files. Be aware, however, that depending where you create file1.txt and file2.txt (Win, Unix, MacOs) the results could differ because the end of line is handled differently in these platforms.

  2. Recall that we studied the use of args in
    public static void main(String[] args)
    in Chapter 5.11.1 (page 177 of our textbook) for commandline arguments. Here are two programs using this utility: CommandLine.java CommandLine2.java.
    Write a program MyCP.java, so that when you type
    java MyCP file1.txt file2.txt
    it behaves like the Unix command cp.
  3. Read the Unix man pages on ls command. Compile and try java LS. What does it do? Study the code LS.java and try to figure out its usage.