有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java 1.4.2读取文件

我试图读取一个简单的文件,然后是一个用户应该选择的文件。不过,我一直会遇到以下错误:

Readzilla.java:37: cannot find symbol

symbol : method FileReader(java.lang.String)

location: class java.io.BufferedReader

line = read.FileReader(newDoc);

这是代码。

import java.io.*;

    public class Readzilla
    {
        public static void main(String[] args) throws IOException
        {
            String line;
            BufferedReader read;
            // BufferedReader "read" reads the file
            BufferedReader in;
            // BufferedReader "in" reads the input sent by the user  
            String loop;
            // "loop" decides whether another document should be read

            in = new BufferedReader(new InputStreamReader(System.in));
            read = new BufferedReader(new FileReader("message.txt"));
            line = read.readLine();

            while(line != null)
            {
                System.out.println(line);
                line = read.readLine();
            }

            // read another document
            System.out.println("Would you like to read another document? (Y/N)");
            loop = in.readLine();
            loop = loop.toUpperCase();

            if (loop == "Y")
            {
                do
                {
                    System.out.println("What file (.txt) would you like to read?");
                    String newDoc = in.readLine();
                    // newDoc reads a text file of the user's choosing
                    line = read.FileReader(newDoc);
                    //  ^ This line constantly gives errors
                    System.out.println("Reading...");
                    line = read.readLine();

                    while(line != null)
                    {
                        System.out.println(line);
                        line = read.readLine();
                    }

                    // read another document
                    System.out.println("Would you like to read another document? (Y/N)");
                    loop = in.readLine();
                }
                while (loop == "Y");    
            }
            else
            {
                System.out.println("Closing Program...");
            }
        }
    }

共 (0) 个答案