使用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.