Java 这个文件读取器(循环)有什么问题?

Java 这个文件读取器(循环)有什么问题?,java,io,ioexception,Java,Io,Ioexception,我编写了一个程序,提示用户选择一个特定的目录。完成后,程序应选择该文件夹中的每个文件,然后在这些文件上执行与此问题无关的其他代码 我的问题是,这些文件一直被捕获在try/catch IO异常中,我无法找出原因 下面是我的文件选择器代码和输出 public class checksumGUI { private checksumFinder cf = new checksumFinder(); private static int returnVal1; private static in

我编写了一个程序,提示用户选择一个特定的目录。完成后,程序应选择该文件夹中的每个文件,然后在这些文件上执行与此问题无关的其他代码

我的问题是,这些文件一直被捕获在try/catch IO异常中,我无法找出原因

下面是我的文件选择器代码和输出

public class checksumGUI {

 private checksumFinder cf = new checksumFinder();
 private static int returnVal1;
 private static int returnVal2;

 public void askDirectory() throws FileNotFoundException, UnsupportedEncodingException, IOException {

    JFileChooser inFileName = new JFileChooser(new File("C:\\Documents and Settings\\lucey01\\Desktop\\Projects\\C0048817\\KOI\\C0048817_PCF_Front"));
    inFileName.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    Component parent = null;

    do {
        returnVal1 = inFileName.showOpenDialog(parent);
        if (returnVal1 == JFileChooser.CANCEL_OPTION) {
            returnVal2 = JOptionPane.showConfirmDialog(null, "Select YES to cancel. Select NO to restart",
                    "Are you sure?", JOptionPane.YES_NO_OPTION);
            if (returnVal2 == JOptionPane.YES_OPTION) {
                System.exit(returnVal2);
            } else {
                checksumGUI.this.askDirectory();
            }
        }
    } while (returnVal1 == JOptionPane.CANCEL_OPTION);


    File folderFile = inFileName.getSelectedFile();
    File[] listOfFiles = folderFile.listFiles();
    for (int i = 0; i < listOfFiles.length; i++) {
        File file = listOfFiles[i];
        if (file.isFile() && file.getName().endsWith(".pcf")) {
         cf.HexFinder(folderFile, null, null, null);
        }else {
          System.out.println("Incorrect filetype:\n" + file.getName() + "\n");
        }
    }
}
}
不正确的文件类型输出对于我测试的文件夹是正确的,但是IOExceptions不是。我知道我的代码分别在每个文件上工作

编辑 在try/catch中使用缓冲读取器的代码调用。当此BufferedReader位于try/catch之外时,我会出现以下错误:

run:
Exception in thread "main" java.io.FileNotFoundException: C:\Documents and Settings\lucey01\Desktop\Projects\C0048817\KOI\C0048817_PCF_Front (Access is denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileReader.<init>(FileReader.java:72)
at robertskostalproject.checksumFinder.HexFinder(checksumFinder.java:24)
at robertskostalproject.checksumGUI.askDirectory(checksumGUI.java:47)
at robertskostalproject.RobertsKostalProject.main(RobertsKostalProject.java:14)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)

谁能看出我哪里做错了?我们将一如既往地感谢您的帮助

查找文件名和扩展名问题。正如您所看到的,这是文件名和扩展名的问题

TSG_C7D4_KOI_BT_MAX_EOL.pcf**.xml**
它正在以.XML而不是.PCF的形式读取文件。

cf.HexFinder(folderFile, null, null, null);
应该读

cf.HexFinder(file, null, null, null);

记录IOException消息,而不是无法读取文件!这将告诉您出了什么问题。它可能是从checksumFinder.HexFinder内部抛出的,但您没有提供该问题的源代码。注意,您没有显示任何HexFinder代码,这使您很难提供帮助,而且您的askDirectory方法是令人惊讶的递归方法。我的HexFinder代码是。它只是在一个文件中查找两个特定的十六进制数,并对它们进行比较。我知道。这些人注定要在那里,也注定要被抓住。谢谢:删除你的文本,只需阅读I/O异常,它会给你更多的线索。就这样!万分感谢!
cf.HexFinder(file, null, null, null);