抛异常
public static void main(String[] args) throws IOException { 
// 第一步:构建一个Scanner对象
// Paths.get这个方法提示编译出错,但我是照着书上的例子写的,请问哪里出问题了?
Scanner in = new Scanner(Paths.get("/home/fangmeng/testFile")); // 第二步:调用input函数族
while (in.hasNextLine()) {
String lineStr = in.nextLine();        // 读取行
System.out.print(lineStr);
} // 关闭输入流
in.close(); 
}

解决方案 »

  1.   

    package test;import java.io.IOException;
    import java.nio.file.Paths;
    import java.util.*;// 演示文件IO方法
    public class Test {
    public static void main(String[] args) throws IOException {
    // 第一步:构建一个Scanner对象
    // Paths.get这个方法提示编译出错,但我是照着书上的例子写的,请问哪里出问题了?
    Scanner in = new Scanner(Paths.get("/home/fangmeng/testFile"));
    // 第二步:调用input函数族
    while (in.hasNextLine()) {
    String lineStr = in.nextLine();
    // 读取行 System.out.print(lineStr);
    }
    // 关闭输入流
    in.close();
    }
    }
    就能通过了,少了 throws IOException 
      

  2.   

    把你的代码包围在trycatch块中
    Scanner in = new Scanner(Paths.get("/home/fangmeng/testFile"));
    这句有个IOException要处理
      

  3.   


    太感谢你们了 你们给出的两种解决方法我都试过可以了另外
    是在linux下,所以没有后缀。