File file = new File(path);
if (file.isDirectory() && file.exists()) {
String[] files = file.list();
for (String string : files) {
updateObject = new UpdateObject();
updateObject.setName(string);
System.out.println(file.getPath() + "/" + string);
结果是这样的:
D:\F\work\java\Workspaces\Happy\xhsd_hprose\WebRoot\WEB-INF\classes\pda/xhsd - Copy (2).exe
D:\F\work\java\Workspaces\Happy\xhsd_hprose\WebRoot\WEB-INF\classes\pda/xhsd - Copy (3).exe
D:\F\work\java\Workspaces\Happy\xhsd_hprose\WebRoot\WEB-INF\classes\pda/xhsd - Copy.exe
D:\F\work\java\Workspaces\Happy\xhsd_hprose\WebRoot\WEB-INF\classes\pda/xhsd.exe
再次测试:
OK啦
本文展示了如何使用Java遍历目录下所有文件,并创建更新对象实例的过程,包括文件路径解析与对象属性设置。
305

被折叠的 条评论
为什么被折叠?



