I am trying to read a simple file and then a file which the user is supposed to select. I keep on getting the following error though:
Readzilla.java:3
Your problem is this line:
line = read.FileReader(newDoc);
There is no method named FileReader on the class BufferedReader, which is how the compiler is interpreting that line. FileReader
is itself a class, and it looks like you're trying to open a new file for reading. Thus, you'd want to say something like:
BufferedReader doc = new BufferedReader(new FileReader(newDoc));
After that, you'd want to replace
line = read.readLine();
with
line = doc.readLine()
because that's how you'd read from the document referenced by the BufferedReader doc
.
Additionally, you have a problem here (twice that I see):
loop == "Y"
In Java, ==
is reference equality only. You absolutely want value equality here so say:
"Y".equals(loop);
This is a common mistake; ==
as reference equality only was a poor design decision IMO.
You cannot invoke a constructor from an object, only when you create the object with 'new'. You would just say 'line = read.readLine();' for the problem line.
BufferedReader
class doesn't have a method called FileReader
.
You can see it in the documentation.
One way of reading a file in Java 1.4.2 is:
try
{
String line;
File file = new File(file);
BufferedReader inFile = new BufferedReader(new FileReader(file));
while((line = inFile.readLine()) != null)
{
System.out.println(line)
}
inFile.close();
}
catch (IOException e)
{
System.out.println("problem with file");
}