Java Input/Output

This worksheet explores your understanding of Java's I/O java.io.* API.

  1. Write a method determines whether a file exists:
    public boolean exists(String name) {
    ...
    }
    
  2. Write a method that lists the contents of a directory:
    public void ls(String name) {
    ...
    }
    
  3. Write a logging method that records a string message to a file, prefixed by a timestamp:
    public void log(String fileName, String msg) {
    ...
    }
    
  4. Write a method that reads 4 characters from System.in and prints them out.
  5. Write "Hi, Mom!" to a StringWriter and then dump the string to make sure you wrote it.