Image

Imagealistairg wrote in Imagejava_dev

Net Beans Question

Hello, I've just joined this community, and I'm a newbie learning Java at university.

I'm running the NetBeans IDE on a computer running windows XP and I'm having problems getting a java program to read files.

I keep getting the error:
java.io.FileNotFoundException: myfile (The system cannot find the file specified)

I also get this error when using an example that I know runs fine under java on debian:


// File reader application

import java.io.*;

class ReadFileApp
{
public static InputStreamReader input =
new InputStreamReader(System.in);
public static BufferedReader keyboardInput = new BufferedReader(input);

public static void main(String[] args) throws IOException
{
FileReader file = new FileReader("football.txt");
BufferedReader MyFile = new BufferedReader(file);

String TeamName; int Position = new Integer(MyFile.readLine()).intValue(); while (Position != 0) { TeamName = MyFile.readLine(); System.out.println(Position+"\t"+TeamName); Position = new Integer(MyFile.readLine()).intValue(); } MyFile.close(); } }


And the file (football.txt):

1
Bayern Informatics
2
Chemistry Casuals
3
Exeter Academicals
4
Friends RE United
0


The file is in the same directory as the .java file, but whenever I execute the program in netbeans I get the following error:

java.io.FileNotFoundException: football.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:106)
at java.io.FileInputStream.(FileInputStream.java:66)
at java.io.FileReader.(FileReader.java:41)
at ReadFileApp.main(ReadFileApp.java:14)
Exception in thread "main"

Any help would be muchly appreciated. Thanks

Edit: All fixed - Thanks guys!