Java 读取文件的方式

Java 读取文件的方式

public class AppleTest {
    @Test
    public void testFileReader() {
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader("D:\\fileUtils.txt"));
            String l = bufferedReader.readLine();
            while (l != null) {
                System.out.println(l);
                l = bufferedReader.readLine();
            }
            bufferedReader.close();

        } catch (IOException ex) {

        }
    }

    @Test
    public void testFilesReaderLine() throws IOException {
        List<String> lists = Files.readAllLines(Paths.get("D:\\fileUtils.txt"));
        lists.forEach(System.out::println);
    }
}

你可能感兴趣的:(Java,java)