哪个高手请教下文件的读写具体怎么操作的?怎么打开一个文件?

解决方案 »

  1.   

    流处理,java.IO包的类;
    一般用BufferredReader和BufferredWriter进行读。使用多线程会麻烦些
      

  2.   

    File f = new File("D:\\a.txt");
    BufferedReader bf = new Bufferedreader(new FileReader(f));
    然后就用bf.readLine。。等等方法去读..
      

  3.   

    http://bbxyhaihua.javaeye.com/blog/540975
    以后先自己搜搜!
      

  4.   

    读文件 文件名你自己换一个存在的public class TestRead {
    public static void main(String[] args)
      throws Exception{
            FileInputStream fis = new 
              FileInputStream("c:\\abc.txt");
            byte[] b = new byte[1024];
            int temp = 0;
            String result = "";
            while(true){
             temp = fis.read(b);
             if(temp==-1) break;
             result = result + 
               new String(b,0,temp);
            }
            fis.close();
            System.out.println(result);
    }
    }写文件import java.io.FileOutputStream;
    public class TestWrite {
    public static void main(String[] args) 
    throws Exception{
            FileOutputStream fos = new 
              FileOutputStream("c:\\dd.txt");
            String temp = "iou";
            fos.write(temp.getBytes());
            fos.close();
    }
    简单的文件拷贝 同样是文件名自己换 import java.io.FileInputStream;
    import java.io.FileOutputStream;public class TestCopy { public static void main(String[] args) 
      throws Exception{
        FileInputStream fis = new 
            FileInputStream("c:\\abc.txt");
    FileOutputStream fos = new 
            FileOutputStream("c:\\dd.txt");
            byte[] b = new byte[1024];
            int temp = 0;
            while(true){
                temp = fis.read(b);
                if(temp==-1) break;
                fos.write(b,0,temp);
            }
            fis.close();       
            fos.close();
    }}
      

  5.   

    接口:
    InputStream:读
    OutputStream:写
    适合二进制/文本文件的读写
    实现类:FileInputStream/ByteArrayInputStreamReader/Wriite
    适合文本文件的读写
    BufferedReader/FileRearer/FileWriter
      

  6.   

    方法很多呀。主要是java.io包中的类。