Mainscannertestjava8 cpsc324spring2010 9 scanner

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: FileNotFoundExcepIon { File aFile = new File(“file.txt ”); Scanner in = new Scanner(aFile); [sbowers:]$ java ScannerTest while(in.hasNextLine()) ExcepIon in thread "main" file.txt (No System.out.println(in.nextLine()); such file or directory) in.close(); at Method) at<init>( } at java.uIl.Scanner.<init>( } at ScannerTest.main( CPSC 324 ‐‐ Spring 2010 9 Scanner example Another solution ... import java.uIl.Scanner; import; Handle the exception import; public class ScannerTest { public staIc void main(String args) { File aFile = new File(“file.txt ”); try { Scanner in = new Scanner(aFile); This is called a while(in.hasNextLine()) System.out.println(in.nextLine()); “try-catch” block in.close(); } catch(FileNotFoundExcepIon e) { // degrade gracefully … } } } CPSC 324 ‐‐ Spring 2010 10...
View Full Document

This document was uploaded on 03/18/2014 for the course CPSC 324 at Gonzaga.

Ask a homework question - tutors are online