File fe = new File("C:\\Users\\" + System.getProperty("user.name") + "\\desktop" + "\\SearchResults.txt");
String customLoca = "C:\\Users\\" + System.getProperty("user.name") + "\\AppData" + "\\roaming" + "\\.minecraft" + "\\mods" + "\\1.7.10";
FileWriter fw = null;
try {
fw = new FileWriter(fe);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
File dir = new File(customLoca);
for (File f : dir.listFiles()) {
if (f.getName().contains("Toggle")){
try {
fw.write("Found: " + f.getName());
fw.write("\r\n===");
fw.write("\r\n");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
try {
fw.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
基本上,上面的代码创建了一个包含结果的文本文档。这可行,但是我必须使其与我希望它找到的文件大小写精确。例如,如果我将“Toggle”替换为“toggle”,则不会出现任何内容。有没有办法让这个不区分大小写?另外,有没有办法可以添加一个 else 参数。因此,如果没有找到任何内容,它将在文本文档中打印“Nothing Found”。谢谢。