Java I/O文件读取问题和程序包

Java I/O文件读取问题和程序包,java,Java,我正在试着让我的程序运行。我需要写一个程序来保存记录并对一个班级的学生进行统计分析。要从文本文件中获取的数据。我第一次使用软件包和I/o文件,但有点卡住了。我得到错误:“线程中的异常”main“java.io.FileNotFoundException:Data.txt(系统找不到指定的文件)” 以下是我的课程: public class ReadSource { public static void main(String [] args) throws Exception

我正在试着让我的程序运行。我需要写一个程序来保存记录并对一个班级的学生进行统计分析。要从文本文件中获取的数据。我第一次使用软件包和I/o文件,但有点卡住了。我得到错误:“线程中的异常”main“java.io.FileNotFoundException:Data.txt(系统找不到指定的文件)”

以下是我的课程:

public class ReadSource
{

        public static void main(String [] args) throws Exception
    {

            Student lab4 [] = new Student[40];

            if (lab4.length > 40)
            {
                System.out.println("Too Many Records");
            }
            lab4 = Util.readFile("Data.txt", lab4);
            Statistics statlab4 = new Statistics();
            statlab4.findlow(lab4);

            StringTokenizer st = new StringTokenizer("this is a test");
            while (st.hasMoreTokens())
            {
                System.out.println(st.nextToken());
            }
        }
}

public class Student
{
    private int SID;       //Student ID
    private Integer scores[] = new Integer[5];
    public int getSID() {
        return SID;
    }
    public void setSID(int SID) {
        this.SID = SID;
    }
    public Integer[] getScores() {
        return scores;
    }
    public void setScores(Integer[] scores) {
        this.scores = scores;
    }

    public String Print()
    {
        Student [] students = new Student[5];
        for (int i = 0; i < students.length; i++)
        {
            return ("SID: " + this.SID + "Scores" + this.scores);
        }
        return ("SID: " + this.SID + "Scores" + this.scores);
    }
}


public class Util
{
    public static Student [] readFile(String filename, Student [] stu)throws Exception
    {

        String x;
        FileReader fr = new FileReader("Data.txt");
        BufferedReader br = new BufferedReader(fr);
        while ((x = br.readLine())!= null)
        {
            System.out.println(x);
        }
        fr.close();
        return stu;
    }
    Student a1[][] = new Student [40][6];  
    public static void read()
    {
    }
}
公共类ReadSource
{
公共静态void main(字符串[]args)引发异常
{
学生lab4[]=新生[40];
如果(lab4.length>40)
{
System.out.println(“记录太多”);
}
lab4=Util.readFile(“Data.txt”,lab4);
Statistics statlab4=新统计数据();
statlab4.findlow(lab4);
StringTokenizer st=新的StringTokenizer(“这是一个测试”);
而(st.hasMoreTokens())
{
System.out.println(st.nextToken());
}
}
}
公立班学生
{
私有int SID;//学生ID
私有整数分数[]=新整数[5];
公共int getSID(){
返回SID;
}
公共无效设置ID(int SID){
this.SID=SID;
}
公共整数[]getScores(){
返回分数;
}
公开考试分数(整数[]分){
这个分数=分数;
}
公共字符串打印()
{
学生[]学生=新生[5];
for(int i=0;i

请帮我找出我做错了什么

请尝试理解抛出的错误消息

我收到错误:“线程“main”中出现异常” java.io.FileNotFoundException:Data.txt(系统找不到 指定的文件“

你从中了解到了什么?在我看来,应用程序(或Java运行时)似乎在说“我找不到名为Data.txt的文件”。作为一名程序员,你现在应该问问自己——这个文件存在吗?若有,;为什么JRE(或我的应用程序)找不到它

可能的解释

文件存储在这里

c:\My Documents\stuff\Data.txt

你的申请在这里

c:\My Documents\programming\myapp.java

当应用程序搜索文件“Data.txt”时,它将在此处查找

c:\My Documents\programming\Data.txt


因为这是相对于应用程序的相对路径。
更改路径,您应该解决您的问题。

给出完整的文件路径