要用到java的“流”,不过那样安全吗?可行性高吗?
客户端也

解决方案 »

  1.   

    /**
    *功能:将一个文件复制粘贴到另一文件夹中,并可改名.路径为文件的绝对路径。
    *@param sourcefile 源文件
    *@param targetfile 目标文件
    *@return true or false
            *@throws FileNotFoundException
            *@throws IOException
    */
    public boolean copyfile(String sourcefile,String targetfile) throws java.io.FileNotFoundException,java.io.IOException
    {
    File v_sourcefile=new File(sourcefile);
    //取系统文件分隔符
    separator=java.lang.System.getProperty("file.separator");
    //取系统文件分隔符完
    if(!v_sourcefile.exists())
    return false;
    //取目标文件的路径
    String tempstring="";
    String tempstring1=targetfile;
    int j=0;
    int j1=separator.length();
    int j2=targetfile.length();
    j=tempstring1.indexOf(separator);
    while(j>=0)
    {
    tempstring+=tempstring1.substring(0,j);
    String tempstring2=tempstring1.substring(j+j1,j2);
    int j3=tempstring2.indexOf(separator);
    if(j3>=0)
    tempstring+=tempstring1.substring(j,j+j1);
    tempstring1=tempstring2;
    j2=tempstring1.length();
    j=j3;
    }
    String newpath = tempstring;
    File f3=new File(newpath);
    if(f3.exists())
    {
    if(!f3.isDirectory())
    {
    return false;
    }
    }
    else
    {
    f3.mkdirs();
    }
    java.io.FileInputStream file1=new java.io.FileInputStream(sourcefile);
    java.io.FileOutputStream file2=new java.io.FileOutputStream(targetfile);
    int abyte;
    while((abyte=file1.read())!=-1){
    file2.write(abyte);}
    file1.close();
    file2.close();
    return true;
    }
      

  2.   

    thanks,但当文件达到10M以上时,经常会出错