import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
/**
*
* @author outofmemory.cn
*/
public class Main {
/**
* Prints some data to a file using a BufferedWriter
*/
public void writeToFile(String filename) {
BufferedWriter bufferedWriter = null;
try {
//Construct the BufferedWriter object
bufferedWriter = new BufferedWriter(new FileWriter(filename));
//Start writing to the output stream
bufferedWriter.write("Writing line one to file");
bufferedWriter.newLine();
bufferedWriter.write("Writing line two to file");
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
//Close the BufferedWriter
try {
java使用BufferedWriter写文件
最新推荐文章于 2024-07-09 22:24:46 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)