Java FileSystem 常用代码片段

67 阅读1分钟

获取当前目录绝对路径

 System.out.println(FileSystems.getDefault().getPath("").toAbsolutePath().toString());

NIO直接往文件写字符串

        Path path = Paths.get("hello.txt");
        try {
            Files.write(path,"hello".getBytes());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }