一次读取文件的全部内容
import java.io.IOException;/* 来自 N o w J a v a . c o m*/ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { public static void main(String[] args) throws IOException { Path path = Paths.get("/home/docs/users.txt"); byte[] contents = Files.readAllBytes(path); for (byte b : contents) { System.out.print((char) b); } } }