import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Testk {
public static void main(String[] args) throws IOException {
copy("G:\\come");
}
/**
* @param string
*/
public static void copy(String string) {
File file = new File(string);
BufferedInputStream fim = null;
BufferedOutputStream fo = null;
File[]fi1=File.listRoots();
for (File fi:fi1){////////////为什么只能执行到这里?
if (fi.isFile()) {
String str = fi.getAbsolutePath();
try {
fim = new BufferedInputStream(new FileInputStream(str));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
fo = new BufferedOutputStream(new FileOutputStream("E"+str.substring(1)));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int ch = 0;
try {
while ((ch = fim.read()) != -1) {
fo.write((char) ch);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (file.isDirectory()) {
copy(string);
}
}
}
}
}
|