用java实现文件copy
package copy.wkjava;ize=2 color=blue>return to;
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;
}
}
}
}
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
阅读:1300
引用:0
OK了
@2006-03-30 22:07:20 weiking
嘿嘿,自己把自己搞蒙了!
The code very Beautiful...
The code very Beautiful...
没问题
@2006-03-30 10:36:36 hofman
站长也犯如此低级错误,害得我还测试一下。
格式
@2006-03-30 10:14:45 weiking
好象是第一次发代码哈,效果不如想象中的好,
都没有变颜色,还是“卓达文摘”里面的代码比较好看!
都没有变颜色,还是“卓达文摘”里面的代码比较好看!
