用java语言编写:任意指定一个目录,统计该目录下jar文件的个数。
1个回答
展开全部
import java.io.File;
import java.util.Stack;
public class MainTest {
public static void main(String[] args) {
File root = new File("F:/backup");
boolean log = false;
int cnt = 0;
if (root.exists() && root.isDirectory()) {
Stack<File> stack = new Stack<File>();
stack.add(root);
while (!stack.isEmpty()) {
File dir = stack.pop();
File[] files = dir.listFiles();
for (File file : files) {
if (file.isDirectory()) {
stack.add(file);
} else if (file.getName().endsWith(".jar")) {
cnt++;
if (log) {
System.out.println(file.getAbsolutePath());
}
}
}
}
}
System.out.println("JAR FILE COUNT: " + cnt);
}
}
import java.util.Stack;
public class MainTest {
public static void main(String[] args) {
File root = new File("F:/backup");
boolean log = false;
int cnt = 0;
if (root.exists() && root.isDirectory()) {
Stack<File> stack = new Stack<File>();
stack.add(root);
while (!stack.isEmpty()) {
File dir = stack.pop();
File[] files = dir.listFiles();
for (File file : files) {
if (file.isDirectory()) {
stack.add(file);
} else if (file.getName().endsWith(".jar")) {
cnt++;
if (log) {
System.out.println(file.getAbsolutePath());
}
}
}
}
}
System.out.println("JAR FILE COUNT: " + cnt);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询