Hea*_*r T 1 java filenames path
我的问题有两部分 - 首先,标题到底是什么 - 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;
}
}
Run Code Online (Sandbox Code Playgroud)