如何能实现文档数据的读入,又如何把处理完的数据读出到其他文档?
------解决方案--------------------
FileReader處理文檔讀
FileWriter處理文檔寫
------解决方案--------------------
i/o 包
------解决方案--------------------
刚给另一个人写的程序,跟你类似,我也没改,直接给你贴出来了,只是相比下多一些判断
import java.awt.Toolkit;
import java.io.File;
import java.io.FileWriter;
import java.io.*;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Iterator;
public class test3{
public test3() {
File f=new File( "f:\\programme ");
if (f.isDirectory()==false)
{
System.out.println( "该文件夹不存在 ");
}
else
{
f.mkdir();
}
File f2=new File( "f:\\programme\\aa.txt ");
if(f2.isFile()==false)
{
System.out.println( "该文件不存在 ");
try {
FileWriter w = new FileWriter( "f:\\programme\\aa.txt ");
w.write( "open ");
w.write( "\n ");
w.write( "window ");
w.close();
}
catch (IOException ex) {
}
}
else
{
try {
FileReader r = new FileReader( "f:\\programme\\aa.txt ");
BufferedReader b=new BufferedReader(r);
String ms=null;
ArrayList list=new ArrayList();
while ((ms=b.readLine())!=null)
{
list.add(ms);
}
Iterator it=list.iterator();
FileWriter w = new FileWriter( "f:\\programme\\aa.txt ");
while (it.hasNext())
{
String gs = (String) it.next();
w.write(gs);
w.write( "\n ");
}
w.write( "open ");
w.write( "\n ");
w.write( "window ");
w.close();
}
catch (Exception ex1) {
}
}
}
public static void main(String[] args) {
test3 test31 = new test3();
}
}