CSE 201 Homework 7
Read Section 4.10 in Chapter 4, and Section 12.1 in Chapter 12
in the textbook, and then answer the following questions.
- Write a statement that declares a Scanner object and
initializes it to get input from the file named
"input_file".
- Implement (i.e., write the body of) the following method,
countLines, that, given a
String parameter, the name of a file, counts and returns
the number of lines of text in the corresponding file.
public static int countLines(String fileName) throws IOException
- Implement a new version of the countLines method
that catches the possible IOException exception and
outputs an error message if such an exception is raised.
public static int countLines(String fileName)
- Implement the following method, sumLines, that, given a
String parameter, the name of a file, reads all the integer
values appearing one per line in the corresponding file and returns
the sum of the integers. Make sure you catch and handle the
possible IOException exceptions.
public static int sumLines(String fileName)
- Write a statement that declares a PrintWriter object and
initializes it to send output to the file named
"output_file".
- Implement the following void method, copyFile, that,
given two String parameters, the names of an input file
and an output file, copies the input file to the output file.
Make sure you catch and handle the
possible IOException exceptions.
public static void copyFile(String inFileName, String outFileName)