import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Testk {
public static void main(String[] args) throws IOException {
copy("G:\\come");
}
public static void copy(String string) throws IOException{
File file = new File(string);
BufferedInputStream fim = null;
BufferedOutputStream fo = null;
File[] fi1 = file.listFiles();
for (File fi : fi1) {
if (fi.isFile()) {
String str = fi.getAbsolutePath();
fim = new BufferedInputStream(new FileInputStream(str));
fo = new BufferedOutputStream(new FileOutputStream("E"
+ str.substring(1)));
int ch = 0;
while ((ch = fim.read()) != -1)
fo.write((char) ch);
}
if (fi.isDirectory()) {
File file2=new File("E"+fi.getAbsolutePath().substring(1));
System.out.println(file2.mkdir());
copy(fi.getAbsolutePath());
}
}
}
}
我想把G盘的文件夹全部复制到E盘。可是老师做不出来。我的问题出在哪啊 ?请各位高手指教
|
|