import java.io.File; import java.util.Scanner; class Demo { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(new File("d:\abc.txt")); System.out.println("文件内容如下:"); while (sc.hasNextLine()) { System.out.println(sc.nextLine()); } } }