gpt4 book ai didi

java - 使用java与temp.getstat匹配时如何匹配目录中的文件

转载 作者:太空宇宙 更新时间:2023-11-04 11:59:42 25 4
gpt4 key购买 nike

如果sql server表中的文件“id”与本地目录上的文件名匹配,我正在编写java编码。如何扫描文件并检查文件名是否匹配而不使用for循环。

String pathJ = "C:\\sampleDirectory"; 
NewsContentObj[] newObj = firstTimeRetrieveRecordFromDB();
for (NewsContentObj temp : newObj) {

File dir = new File("C:\\sampleDirectory");
File[] files = dir.listFiles();
Arrays.sort(files);

for (File file : files){
String path1 = file.getAbsolutePath();
String path = file.getName();

if(temp.getStat().equals(file)){
System.out.println("first path:" + file );
//System.out.println("first path1:" + files[i].getName());
cacheStaticL(pathJ,path);
}
//}
}
}

谢谢

最佳答案

您可以使用以下代码检查给定目录中是否存在文件

boolean check = new File(directory, temp).exists();

关于java - 使用java与temp.getstat匹配时如何匹配目录中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41032470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com