如果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/