【发布时间】:2014-06-17 13:18:52
【问题描述】:
我的问题有两个部分 - 首先,标题到底是什么 - Path.getNameCount() 方法实际计数的是什么?当您在 Eclipse 中选择方法时,我阅读了它附带的小弹出信息,我认为这是一个合适的用法。我使用它创建的这个方法在运行时返回 5 作为 int。其次,我尝试要做的是返回目标目录中有多少文件,这样我就可以运行另一个方法,我必须多次检索文件名。如果 getNameCount() 方法不适用于此功能,您对如何实现相同目的有什么建议吗?
//Global Variable for location of directory
Path dir = FileSystems.get("C:\\Users\\Heather\\Desktop\\Testing\\Testing2");
//Method for collecting the count of the files in the target directory.
public int Count()
{
int files=0;
files = dir.getNameCount();
return files;
}
}
【问题讨论】:
-
FileSystems.getDefault().getPath应替换为Paths.get