import java.io.*;
import java.io.RandomAccessFile;public class Untitled3 {
  public static void main(String[] ss){
    File fileRead=new File("C:/data.exe");
    File fileCopy=new File("C:/data复件.exe");
    byte[] bs=null;
    try{
      fileCopy.createNewFile();
      RandomAccessFile readFile=new RandomAccessFile(fileRead,"rw");
      RandomAccessFile writeFile=new RandomAccessFile(fileCopy,"rw");
      int count=1;
      while(count>0){
        bs = new byte[1024];
        readFile.read(bs, 0, 1024);
        writeFile.write(bs,0,count);
      }
    }catch(IOException e){
      e.printStackTrace();
    }
  }
}看看,行不?

解决方案 »

  1.   

    我自己的也行了,呵呵,怎么结帐啊??我的价钱出高了
    import java.io.*;
    public class saveToFile{
       public static void main(String args[]){
        byte t[]=new byte[1024];
        try{
        FileInputStream fis=new FileInputStream("E:\\KECHENGSHEJI\\wangzhaohui.jpg");       FileOutputStream fos=new FileOutputStream("E:\\KECHENGSHEJI\\out.jpg");
           int i;
           while((i=fis.read(t))!=-1)
           {
            fos.write(t);
           }
      }
      catch(IOException e)
      {
     
      }
     }
    }
      

  2.   

    你的方法也不错!:)但是fis.read(t))每次读一个字节,频繁进行io操作对效率有一定影响,还是建议每次读一个较大的块。>>>我的价钱出高了
    那我开个帖子还你一些分?哈哈
      

  3.   

    Kao,连buffer都没用到,大文件读取小心死机哦:)
      

  4.   

    看看下面这个方法,效率不错:
    public void openFile() {
    String fname = null;
    JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(NotePad.this);
    if(returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    try{
    FileReader fr = new FileReader(file);
    BufferedReader br = new BufferedReader(fr);
    StringBuffer sb = new StringBuffer();
    int i;
    while((i = br.read())!= -1){
    sb.append((char)i);
    }
    ta.setText(sb.toString());
    }catch (Exception e) {
    // XXX: handle exception
    }
    } else {
    return;
    }
    }
      

  5.   

    按照 guitarking(社会青年) 的方法,应该怎么样写文件呢?