-
January 1st, 2013, 02:51 AM
#1
Program isn't reading my .txt file
Greeting,
I’m using netbeans on a MacBook. I’ve written a small program that reads a text file. However, the program isn’t reading the file. I’m receiving my FileNotFoundExepection error message. Where can I place my out.txt file so that the program is able to locate the file in this simple code below.
public class TextFileInputDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String fileName = "out.txt";
Scanner inputStream = null;
System.out.println("The file " + fileName +
"\ncontains the following lines:\n");
try
{
inputStream = new Scanner(new File(fileName));
}
catch (FileNotFoundException e)
{
System.out.println("Error opening the file " + fileName);
System.exit(0);
}
while (inputStream.hasNextLine());
{
String line = inputStream.nextLine();
System.out.println(line);
}
inputStream.close();
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|