Reader in = new FileReader(f);
char[] buff = new char[4096];
int nch;
while ((nch = in.read(buff, 0, buff.length)) != -1) {
doc.insertString(doc.getLength(), new String(buff, 0, nch), null);
}
这是java的demo中的例子,你可以借鉴,速度相当之快,因为他外面套用了线程,你也可以加入线程,另外他的运做模式是以每4096个char的数组为单位,因为数组在java中是最快的,所以效率相当高,当然你也可以改变4096这个数字来根据自己的机器提高效率

解决方案 »

  1.   

    我才刚学 
    还不想 自定义 Buffer  ,我问一下
    为什么
    PrintWriter out =new PrintWriter(
                           new BufferedWriter(
                            new FileWriter("xx2.txt")));
    不能读取
         BufferedReader in =new BufferedReader(
                             new InputStreamReader(System.in));
    呢?还有
    DataOutputStream out2=new DataOutputStream(
                               new BufferedOutputStream(
                                new FileOutputStream("xx3.txt")));
    out2.writeDouble(1565.565);不能写进去呢?
    谢谢~
            
      

  2.   

    把while(in.readLine()!=null)改为while((in.readLine).length()!=0)
      

  3.   

    改了
    第一次  输入 一个字符传,  再输入 空格 ,可以终止 程序,我想写的txt中还是 没有内容!
      

  4.   

    hehe,我给你稍微改了一下,你一运行就知道为什么没有内容了
    import java.io.*;public class IOBufferedWriter{
    public static void main(String[] args) throws IOException{
    BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out =new PrintWriter(new FileWriter("xx2.txt"),true);
    DataOutputStream out2=new DataOutputStream(new BufferedOutputStream(new FileOutputStream("xx3.txt"))); try {
    System.out.println("Please input the string: ");
    System.out.println(in.readLine()); while((in.readLine()).length()!=0){
    System.out.println("in.readLine() = " + in.readLine());
    out.write("5");
    out2.writeDouble(1565.565);
    }
    in.close(); }catch (EOFException e) {
    System.out.println("End of Scream");
    }
    }
    }
      

  5.   

    上面的一句话,好像循环,下面的根本就没有执行,
    out.write("5");
    out2.writeDouble(1565.565);
    我在命令行 和  Gel中的结果都不一样,这是怎么回事>
      

  6.   

    我也可了,反复用,最后只剩下了
    import java.io.*;public class IOBufferedWriter{
    public static void main(String[] args) throws IOException{
    PrintWriter  f  =  new  PrintWriter(new  FileWriter("xx2.txt"),true);  
    f.write("sgggggggggggg");
    }
    }
    结果还是没有结果写进去,我也不知道为什么
      

  7.   

    to:  回复人: mymoto(忽忽)  加上 flush(),close()
    你的可以了!,但是  还不能从 System.in中读