集册 Java实例教程 使用BufferedWriter类写入文件

使用BufferedWriter类写入文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

515
使用BufferedWriter类写入文件
// 来 自 时 代 J a v a - N o w J a v a . c o m

import java.io.BufferedWriter;

import java.io.IOException;

import java.nio.charset.Charset;

import java.nio.file.Files;

import java.nio.file.Path;

import java.nio.file.Paths;

import java.nio.file.StandardOpenOption;


public class Main {

  public static void main(String[] args) throws IOException {

    try {

      String newName = "Vivian";

      Path file = Paths.get("/home/docs/users.txt");

      try (BufferedWriter writer = Files.newBufferedWriter(file, Charset.defaultCharset(), StandardOpenOption.APPEND)) {

        writer.newLine();

        
展开阅读全文