集册 Java实例教程 保存到具有缓冲流的文件

保存到具有缓冲流的文件

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

538
使用缓冲流保存到文件

import java.io.BufferedWriter;/* 来 自 N o w J a v a . c o m - 时  代  Java*/

import java.io.IOException;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

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) {

    Path path = Paths.get("C:/folder1/equipment", "test.txt");

    String string = "\ntest";


    try (OutputStream outputStream = Files.newOutputStream(path,

        StandardOpenOption.APPEND);

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
        
展开阅读全文