Java 1.4.2 - Reading Files

后端 未结 3 1274
南笙
南笙 2020-12-22 06:58

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

3条回答
  •  不知归路
    2020-12-22 07:19

    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.

提交回复
热议问题