Read line using Java New I/O

前端 未结 3 1676
执念已碎
执念已碎 2021-01-21 07:49

What\'s the best way to read a line from a file using the New I/O ?

I can only get a byte at a time.

Any idea?

3条回答
  •  [愿得一人]
    2021-01-21 08:37

    Or for small files you can do this:

    List smallFilesLines =  Files.readAllLines(  
    FileSystems.getDefault().getPath("smallFile.txt"), StandardCharsets.UTF_8);  
    
    for (String oneLine : smallFilesLines) {
       System.out.println(oneLine); 
    }
    

提交回复
热议问题