求解两道java题目,请发送源代码! 50
1个回答
展开全部
第二题的
import java.io.File;
public class FileList {
public static void printContentInOneDirectory(File path, int depth) {
for(int i = 0; i < depth; i++)
System.out.print("--");
if(path.isDirectory())
System.out.print("[目录] ");
else
System.out.print("[文件] ");
System.out.println(path.getName());
}
public static void readFileAndDirectory(File path, int depth) {
if(path.exists()) {
printContentInOneDirectory(path, depth);
if(path.isDirectory()) {
File[] files = path.listFiles();
for(File file : files)
readFileAndDirectory(file, depth + 1);
}
}
}
public static void main(String[] args) {
FileList.readFileAndDirectory(new File("D:/GIF Movie Gear"), 0);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询