我尝试了下面发布的方法,但仍然没有成功。我收到找不到符号的错误。我还能如何修改下面的代码。我必须将线放在底部吗?

import java.util.Scanner;
import java.io.*;
import java.util.Arrays;
/**
 * Write a description of class lab8 here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class lab8
{
     public static void main(String[] args) throws IOException
   {
   FileInputStream fileIn = new FileInputStream("haikuFun.txt");
   Scanner scrn = new Scanner(fileIn);
   String[] lines = fileIn.readAllLines(new File("haikuFun.txt").toPath());
   while(scrn.hasNext()) {
     String s = scrn.nextLine();
     System.out.println(s);
    }

  }
}

最佳答案

我会像这样使用Files.readAllLines(Path)

String[] lines = Files.readAllLines(new File("haikuFun.txt").toPath());

10-08 18:58