Java 无法将ReadFile解析为类型 我是个新手,我在网上搜索了几个小时来解决我的问题,但仍然没有运气。p>

Java 无法将ReadFile解析为类型 我是个新手,我在网上搜索了几个小时来解决我的问题,但仍然没有运气。p>,java,readfile,Java,Readfile,我真的很想了解java,如果您能解释一些细节,我将不胜感激 问题就在这方面 ReadFile file = ReadFile(file_name); error message : "ReadFile cannot be resolved to a type." 这是我的代码:FileData.java package textfiles; import java.io.IOException; public class FileData { public static voi

我真的很想了解java,如果您能解释一些细节,我将不胜感激

问题就在这方面

ReadFile file = ReadFile(file_name);

error message : "ReadFile cannot be resolved to  a type."
这是我的代码:
FileData.java

package textfiles;
import java.io.IOException;

public class FileData {

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

        String file_name = "D:/java/readfile/test.txt";

        try {

            ReadFile file = ReadFile(file_name);
            String[] aryLines = file.OpenFile();


            int i;
            for (i =0; i < aryLines.length ; i++) {

                System.out.println( aryLines[i] );
            }

        }
        catch (IOException e) {

            System.out.println( e.getMessage() );
        }

    }       
}
package textfiles;

import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;

public class ReadFile {

    private String path;

    public ReadFile (String file_path) {

        path = file_path;

    }
    int readLines () throws IOException{

        FileReader file_to_read = new FileReader(path);
        BufferedReader bf = new BufferedReader(file_to_read);

        String aLine;
        int numberOfLines = 0;

        while (( aLine = bf.readLine() )  != null) {

            numberOfLines++;

        }

        bf.close();

        return numberOfLines;
    }
    public  String[] OpenFile () throws IOException {

        FileReader fr = new FileReader (path);
        BufferedReader textReader = new BufferedReader (fr);


        int numberOfLines = readLines();
        String[] textData = new String[numberOfLines];

        int i;

        for (i=0; i < numberOfLines; i++) {

            textData[i] =textReader.readLine();
        }


        textReader.close();
        return textData;
    }
}
试试这个:

ReadFile file = new ReadFile(file_name);
为了使用对象的类名初始化对象,您应该使用如下的
new
关键字:

ClassName objName = new ClassName(arguments);
从代码的其余部分来看,您似乎知道这个概念,不过我建议您(或未来可能的访问者)访问页面