打印文件中的内容

package intensiveexercise;

import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.stream.Stream;

public class Q12Files {

 public static void main(String[] args) {   

//  Path path = Paths.get("courses.txt");

//  Stream<String> fc = null;

//  try { //   fc = Files.lines(path);

//   

//   List<String> fcList = Files.readAllLines(path);

//   

//  } catch (IOException e) {

// 

//   e.printStackTrace();

//  }

//  fc.forEach(s -> System.out.println(s));      

Path file=Paths.get("Q:/Users/a496006.DMN1.000/Desktop/s.txt");     

 try {    Stream<String> fc=Files.lines(file);    

fc.forEach(s->System.out.println(s));    

//   List<String> fcList= Files.readAllLines(file);

//   fcList.forEach(s->System.out.println(s));  

 } catch (IOException e) {   

   e.printStackTrace();   }   

 }

}

原文地址:https://www.cnblogs.com/mabel/p/6291898.html