集册 Java实例教程 读取作为列表返回的文件的所有行

读取作为列表返回的文件的所有行

欢马劈雪     最近更新时间:2020-01-02 10:19:05

409
读取以列表形式返回的文件的所有行

import java.io.IOException;/** from 时代Java - nowjava.com**/

import java.nio.charset.Charset;

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.Paths;

import java.util.List;


public class Main {

  public static void main(String[] args) throws IOException {

    try {

      Path path = Paths.get("/home/docs/users.txt");

      List<String> contents = Files.readAllLines(path, Charset.defaultCharset());

      for (String b : contents) {

        
展开阅读全文