求助大佬
java吧
全部回复
仅看楼主
level 11
朕不灭 楼主
import java.io.PrintWriter;
public class Test3 {
public static void main(String[] args) throws IOException {
File dirPath = new File("D:\\moniceshitibefore81");
File destPath = new File("result.txt");
copyPathToFile(dirPath, destPath);
}
private static void copyPathToFile(File dirPath, File destPath) throws IOException {
File[] files = dirPath.listFiles();
PrintWriter out = new PrintWriter(new FileWriter(destPath), true);
for (File file : files) {
if (file.isDirectory()) {
copyPathToFile(file, destPath);
} else if (file.isFile() && file.getName().endsWith(".java")) {
out.println(file.getAbsolutePath()+true);
System.out.println(file);
}
}
out.close();
}
}
【冒泡】名字被和谐了 2018/7/31 14:07:35
大佬看下
【冒泡】名字被和谐了 2018/7/31 14:08:06
为什么我输出的只有最后一个文件夹的文件
你撤回了一条消息
【冒泡】名字被和谐了 2018/7/31 14:09:08
【冒泡】名字被和谐了 2018/7/31 14:09:23
2018年07月31日 06点07分 1
level 11
朕不灭 楼主
2018年07月31日 06点07分 2
level 11
朕不灭 楼主
其实有很多文件
D:\moniceshitibefore81\src\Test1\Student.java
D:\moniceshitibefore81\src\Test1\Test1.java
D:\moniceshitibefore81\src\Test1\Test2.java
D:\moniceshitibefore81\src\Test2\Book.java
D:\moniceshitibefore81\src\Test2\Test1.java
D:\moniceshitibefore81\src\Test2\Test2.java
D:\moniceshitibefore81\src\Test3\Test1.java
D:\moniceshitibefore81\src\Test3\Test2.java
D:\moniceshitibefore81\src\Test3\Test3.java
2018年07月31日 06点07分 3
level 11
朕不灭 楼主
10
2018年07月31日 06点07分 4
level 11
朕不灭 楼主
9
2018年07月31日 06点07分 5
level 6
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class Test3 {
static PrintWriter out;
public static void main(String[] args) throws IOException {
File dirPath = new File("D://moniceshitibefore81");
File destPath = new File("D://result.txt");
out= new PrintWriter(new FileWriter(destPath), true);
copyPathToFile(dirPath, destPath);
out.close();
}
private static void copyPathToFile(File dirPath, File destPath) throws IOException {
File[] files = dirPath.listFiles();
for (File file : files) {
if (file.isDirectory()) {
copyPathToFile(file, destPath);
} else if (file.isFile() && file.getName().endsWith(".java")) {
out.println(file.getAbsolutePath());
System.out.println(file);
}
}
}
}
自己复制粘贴进去测试就知道了
2018年07月31日 08点07分 7
谢谢
2018年08月01日 03点08分
1