import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
/** Not really a good descriptive class name, but I don't know
* what you're planning to do with it. You can pick a better one.
*/
public class FileProcessor {
private Scanner filescan = null;
/** Create an instance of FileProcessor for the given File. */
public FileProcessor(File targetFile) throws FileNotFoundException {
filescan = new Scanner(targetFile);
}
/** Processing operations are carried out by calling
* public methods on an instance of this class.
*/
public void printFile() throws IOException {
while (filescan.hasNextInt()) {
System.out.println(filescan.nextInt());
}
}
/** main() can be used as a "driver" to manipulate an instance
* of this class. It should not do anything directly with the internal
* variables. All operations should be accessed only through
* methods provided by the class.
*/
public static void main(String[] args) {
File targetFile = new File("t.txt");
try {
FileProcessor fileProcessor = new FileProcessor(targetFile);
fileProcessor.printFile();
} catch (FileNotFoundException fnf) {
System.out.println("Target file: " + targetFile + " not found.");
System.exit(1);
} catch (IOException ex) {
System.out.println("An IO error occurred processing this file");
ex.printStackTrace();
System.exit(1);
}
}
}