/*自己整理一下吧*/
String source = "d:/websrc/aaa.txt";
String aim = "d:/websrc/aaa.bak";
FileInputStream in = new FileInputStream(source);
FileOutputStream out = new FileOutputStream(aim);
byte[] buffer = new byte[1024];
int length = -1;
while((length=in.read(buffer))!=-1){
out.write(buffer,0,length);
}
out.flush();
out.close();
in.close();

解决方案 »

  1.   

    //:exectest.java
    import java.io.*;class exectest
    {
      public static void main(String[] args)
      {
        try {
          String cmd = "cmd /c copy web.html newweb.html";
          //String cmd = "E:\\Program Files\\Internet Explorer\\IEXPLORE.EXE";
          Process child = Runtime.getRuntime().exec(cmd);
         } catch (IOException e) {
          System.err.println(e);
        }
      }}
      

  2.   

    同意楼上,这是简单的方法,兄弟们还有没有更好的啊,
    我只知道vb,vc中直接可以copy的,不知道java中有没有
      

  3.   

    规定1024大小不太好吧?int c;
    while((c=ifs.read())!=-1){
        ofs.write(c);
    }
      

  4.   

    public static void copyfile(String str,String str1) throws FileNotFoundException {
    try {
    File file=new File(str);
    InputStream is=null;
    OutputStream os=null;
    byte[] b;
    File f=new File(str1);
    if(!file.isDirectory()) {
      is=new FileInputStream(str);
      b=new byte[is.available()];
      is.read(b);
      os=new FileOutputStream(str1);
      os.write(b);
      is.close();
      os.close();
      return;
    } else if(!f.exists())
      f.mkdirs();
    File[] filename=file.listFiles();
    for(int i=0;i<filename.length;i++) {
        copyfile(filename[i].getAbsolutePath(),str1+"/"+filename[i].getName());
    }
    } catch(IOException ex) {
    filecopycount++;
    System.out.println("filecopycount:"+String.valueOf(filecopycount));
    if(filecopycount<=5)
    copyfile(str,str1);
    System.err.println("err:"+ex.toString());
    }
    }