🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### IO * StandardCharsets:字符集常量类 ### 获取文件流&&工具类Files ``` InputStream is = Files.newInputStream(Paths.get("")); OutputStream os = Files.newOutputStream(Paths.get("")); byte[] bytes = Files.readAllBytes(Paths.get("")); //读取所有字节 Files.readAllLines(Paths.get("")); Files.lines(Paths.get("")); // 追加文件 Files.write(Paths.get(""), "".getBytes(), StandardOpenOption.APPEND); Files.write(Paths.get(""), Arrays.asList(""), StandardCharsets.UTF_8, StandardOpenOption.APPEND); // 随机读写文件 RandomAccessFile file = new RandomAccessFile(Paths.get("").toFile(), "rw"); // 内存映射文件 FileChannel channel = FileChannel.open(Paths.get(""), StandardOpenOption.READ, StandardOpenOption.WRITE); ByteBuffer buffer = channel.map(MapMode.READ_WRITE, 0, channel.size()); buffer.put("hello".getBytes()); //文件锁 channel.lock(); channel.tryLock(); // 删除文件 Files.delete(Paths.get("")); // 如果指定的文件或目录不存在则抛出异常 Files.deleteIfExists(Paths.get("")); ``` #### StandardCopyOption ![](../assets/20171208230301.png) #### StandardOpenOption ![](../assets/20171208230448.png)![](../assets/20171208230521.png)