用java实现文件copy
package copy.wkjava;
import java.io.*;
import javax.swing.ProgressMonitorInputStream;

class Copy {
public Copy() {
super();
}
public static void main(String[] args) {
String from = args[0];
String to = args[1];
Copy copy = new Copy();
try {
copy.copy(from,to);
} catch (IOException e) {
e.printStackTrace();
}
}
private void copy(String from, String to) throws IOException {
to = ProcessTo(from,to);
InputStream in = new ProgressMonitorInputStream
(null,"正在复制文件"+from+"到"+to,new BufferedInputStream(
new FileInputStream(from)));
OutputStream out = new BufferedOutputStream(
new FileOutputStream(to));
for (int b=in.read();b!=-1;b=in.read()){
out.write(b);
}
in.close();
out.close();
}
private String ProcessTo(String from, String to) {
File toFile = new File(to);
File fromFile = new File(from);
if(toFile.isDirectory()){
return toFile.getAbsoluteFile() +
File.separator + fromFile.getName();
}
return to;
}
}
ize=2 color=blue>return to;
}
}
lue>for (int b = in.read(); b != -1; b = in.read())
            out.write(b);
        in.close();
        out.close();  
    }
}
weiking   2006-03-30 10:10:05 评论:6   阅读:1554   引用:0
OK了 @2006-03-30 22:07:20  weiking
嘿嘿,自己把自己搞蒙了!
The code very Beautiful...
没问题 @2006-03-30 10:36:36  hofman
站长也犯如此低级错误,害得我还测试一下。
格式 @2006-03-30 10:14:45  weiking
好象是第一次发代码哈,效果不如想象中的好,
都没有变颜色,还是“卓达文摘”里面的代码比较好看!

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

用,就用的漂亮点。文章嘛,借花献佛喽。