集册 Java实例教程 使用BufferedWriter和FileWriter将文本字符串保存到文件

使用BufferedWriter和FileWriter将文本字符串保存到文件

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

537
使用BufferedWriter和FileWriter将文本字符串保存到文件中
/*from NowJava.com*/

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

 

public class Main {

       

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

                StringBuffer sbf = new StringBuffer();

               

                sbf.append("StringBuffer contents first line.");

                //new line

                sbf.append(System.getProperty("line.separator"));

                //second line// from N o w J a v a . c o m

                sbf.append("StringBuffer contents second line.");

               

                BufferedWriter bwr = new BufferedWriter(new FileWriter(new File("d:/demo.txt")));

               

                //write contents of StringBuffer to a file

                bwr.
展开阅读全文