把 copy()移下去就好了
只不过 你这是创建了一个名字一样的空文件,没有实现复制
- import java.io.File;
- import java.io.IOException;
- public class Tesg {
- public static void main(String[] args) throws IOException {
- File file = new File("D:\\myjava\\myself");
- copy(file);
- }
- public static void copy(File file) throws IOException {
- System.out.println("ahh");
- File[] fi = file.listFiles();
- for (File fil : fi) {
- if (fil.exists() && !fil.isHidden() && fil.isFile()) {
- File f = new File("E" + fil.getAbsolutePath().substring(1));
- System.out.println(f.createNewFile());
- }
- else if (fil.exists() && !fil.isHidden() && fil.isDirectory()) {
- File f = new File("E" + fil.getAbsolutePath().substring(1));
- System.out.println(f.mkdirs());
- System.out.println("E" + fil.getAbsolutePath().substring(1));
- [color=Red]copy(fil);[/color]
- }
- }
- }
- }
复制代码 |