這是我的代碼,用它的文件名搜索文本文件。 這個程序沒有錯誤,但我不知道代碼是否正確搜索。如果在消息對話框中沒有找到「文件未找到」文件,我想獲取「找到文件」消息。所以任何一個對我有困難有想法的人都請幫助我。如何在if語句條件中使用搜索到的文本文件?
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
File dir = new File("C:\\Users\\EmuD\\Documents\\NetBeansProjects\\Bank Project");
File[] matchingFiles = dir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
String search = jTextField1.getText();
return name.startsWith(search) && name.endsWith(".txt");
}
});
}
非常感謝!
有什麼困難? –