文件读取和写出
利用files类对文件进行读和写,里面的方法自带关闭流 (jdk7里的try-with-resouese)
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

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

更多精彩