如何列出当前目录中的文件? [英] How to list the files in current directory?
问题描述
文件dir = new File( );
File [] filesList = dir.listFiles(); (文件file:filesList){
if(file.isFile()){
System.out.println(file.getName());
$ b $返回 .classpath
,但我很确定在这个文件夹里有其他的java文件。也许当前文件夹的点符号是不正确的?
解决方案
也许当前文件夹的点符号是不正确?
打印 File.getCanonicalFile()
检查路径。
任何人都可以向我解释为什么src不是当前文件夹吗?
您的IDE在调用JVM时设置了类路径。
EG (达到Netbeans)如果您选择菜单文件
| 项目属性(所有类)
您可能会看到类似于以下内容的内容:
$ b
它是工作目录
在这里感兴趣。
I want to be able to list the files in the current directory. I've made something that should work but doesn't return all the file names.
File dir = new File(".");
File[] filesList = dir.listFiles();
for (File file : filesList) {
if (file.isFile()) {
System.out.println(file.getName());
}
}
It returns .classpath
, but I'm quite sure I have other java files inside this folder. Maybe the dot notation for current folder is incorrect?
解决方案
Maybe the dot notation for current folder is incorrect?
Print the result of File.getCanonicalFile()
to check the path.
Can anyone explain to me why src isn't the current folder?
Your IDE is setting the class-path when invoking the JVM.
E.G. (reaches for Netbeans) If you select menus File
| Project Properties (all classes)
you might see something similar to:
It is the Working Directory
that is of interest here.
这篇关于如何列出当前目录中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!