{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

FileRead - name entered is incorrect or not found the code...

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

View Full Document Right Arrow Icon
/** * Jesus Campos * CS-116-004 * Final Project - Id Class * The file read class takes in a file nanme as an argument. It reads one line at a time and makes that line * into a string. Once this is done it goes to the next line and makes it a string, and so on. **/ package code2; p import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; i public class FileRead { BufferedReader inFile; public FileRead(String inputFile) //inputFile is the name of the file to be read. Make sure to add file extension, i.e. file.txt { try //this method uses a try/catch statement; if the file
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: name entered is incorrect or not found, the code will not execute and it also prevents the system from crashing { inFile = new BufferedReader(new FileReader(inputFile)); } catch(FileNotFoundException fnfe) { System.out.println("File not found"); //if the file name is not found, the user is made aware of this with the message "file not found". } } public String readLine() { String line = ""; try { line = inFile.readLine(); //each line from the file is assigned as a string } catch(IOException ioe) { System.out.println("File Not Found"); } return line; } }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online