Java 1.7+ 读写文件操作

public class FileIO {
     
    public static void main(String[] args) throws IOException {
     
        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get("/Users/mbh/Downloads/a.txt"), StandardCharsets.UTF_8)) {
     
            bufferedWriter.write("dadada");
        }


        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get("/Users/mbh/Downloads/a.txt"), StandardCharsets.UTF_8, StandardOpenOption.APPEND)) {
     
            bufferedWriter.write("mnfkasjflajdlakpd ka");
        }
    }
}

你可能感兴趣的:(java)