文件读取和写出

利用files类对文件进行读和写,里面的方法自带关闭流 (jdk7里的try-with-resouese)

 

 try {
        byte[] bytes = Files.readAllBytes(Paths.get("E:\\testAutoCloseable.txt"));
        String s = new String(bytes, StandardCharsets.UTF_8);
        Files.write(Paths.get("E:\\testAutoCloseable1.txt"), s.getBytes());
    } catch (IOException e) {
        e.printStackTrace();
    }
View Code

 

 

posted @ 2019-04-16 10:19  向前向后看  阅读(176)  评论(0编辑  收藏  举报