首先是从一个指定的文件中读出数据.
public String reader(){
StringBuffer sb = new StringBuffer();
try{
BufferedReader br = new BufferedReader(new FileReader("D:\\log.txt"));
String temp ;
while((temp=br.readLine())!=null){
sb.append(temp) ;
br.close();
}
}catch(Exception e){
e.printStackTrace() ;
}
return sb.toString();
}
然后是把指定的字符串写入文件中(追加形式).
public void writer(String code) {
File tofile=new File("D:\\log.txt");
FileWriter fw=new FileWriter(tofile,true);
BufferedWriter bw=new BufferedWriter(fw);
PrintWriter pw=new PrintWriter(bw);
pw.println(code);
pw.close();
bw.close();
fw.close();
}
posted on 2006-06-16 17:47
我心依旧 阅读(1292)
评论(0) 编辑 收藏