将C:/下的a.txt文件拷贝到D:/下,并改名为b.txt

解决方案 »

  1.   

    File file = new File("a");
    file.rename()
      

  2.   

    The easiest way is to use CMD commands to copy a file...^_^
      

  3.   

    是用IO进行操作吗
    try{
    FileInputStream input=new FileInputStream("c//a.txt");
    }catch(FileNotFoundException e){}
    FileOutputStream out=new FileOutputStream("d//b.txt");
    int len;
    byte[] b=new byte[1024];
    while((len=input.read(b))!=-1)
       out.write(b,0,len);
    input.close();
    out.close();
      

  4.   

    用Java的流的话,像ls的就可以达到效果,但是不建议用1024,建议用int len = file.avaible(),然后读len个长度,一次就ok
      

  5.   


    package first;import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;public class File_copy { public static void main(String[] args) {
    File file=new File("d:\\b.txt");
    FileInputStream fileIn = null;
    FileOutputStream fileOut = null;
    byte[] b=new byte[1024];

    try {
    fileIn=new FileInputStream("c:\\a.txt");
    fileOut = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    try {
    while(fileIn.read()!=-1){
    fileIn.read(b);
    fileOut.write(b, 0, b.length);
    fileOut.flush();
    }
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    try {
    fileIn.close();
    fileOut.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } }}