Я пытаюсь прочитать простой файл, а затем файл, который должен выбрать пользователь. Я продолжаю получать следующее сообщение об ошибке, хотя:Java 1.4.2 - Чтение файлов
Readzilla.java:37: не могу найти символ
символ: метод FileReader (java.lang.String)
местоположение: класс 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...");
}
}
}
попытка заменить Erroneus линию чтения = новый BufferedReader (новый FileReader ("newDoc")); – ice
@ice: Нет кавычек, 'newDoc' является' String'. – jason
Возможно, попробуйте указать кодировку для файла, а не предполагать кодировку по умолчанию. –