用Java生成文本文件(收集)
类别: JAVA教程
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
public class Result {
private File result =new File("result.txt");
private FileWriter writer;
private PrintWriter pw;
public Result() {
try {
writer = new FileWriter("result.txt");
pw=new PrintWriter(writer);
}
catch (IOException iox){
System.err.println(iox);
}
}
public void aLine(String in) { //写入一行
pw.println(in);
}
public void finish() { //关闭输入流,将文字从缓存写入文件
try{
pw.flush();
writer.close();
}catch (IOException iox){
System.err.println(iox);
}
}
}
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
public class Result {
private File result =new File("result.txt");
private FileWriter writer;
private PrintWriter pw;
public Result() {
try {
writer = new FileWriter("result.txt");
pw=new PrintWriter(writer);
}
catch (IOException iox){
System.err.println(iox);
}
}
public void aLine(String in) { //写入一行
pw.println(in);
}
public void finish() { //关闭输入流,将文字从缓存写入文件
try{
pw.flush();
writer.close();
}catch (IOException iox){
System.err.println(iox);
}
}
}
- 上一篇: java日记:学习java一年体会2
- 下一篇: java中文问题-浅析
-= 资 源 教 程 =-
文 章 搜 索