Java 1.4.2 - Reading Files

后端 未结 3 1270
南笙
南笙 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:26

    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");
    }
    

提交回复
热议问题