Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 搜索代码无法搜索音频和视频文件_Java - Fatal编程技术网

Java 搜索代码无法搜索音频和视频文件

Java 搜索代码无法搜索音频和视频文件,java,Java,我用java开发了一个基于桌面的搜索项目。我递归调用了搜索函数来执行搜索操作 我的项目运行良好,但无法搜索音频和视频文件的名称 我正在输入搜索代码 public void searchFiles(String mainPath, String searchText){ mainFile = new File(mainPath); System.out.append(mainF

我用java开发了一个基于桌面的搜索项目。我递归调用了搜索函数来执行搜索操作

我的项目运行良好,但无法搜索音频和视频文件的名称

我正在输入搜索代码

     public void searchFiles(String mainPath, String searchText){
                            mainFile = new File(mainPath);
                            System.out.append(mainFile.getAbsolutePath());
                            File[] roots = mainFile.listFiles();
                            Arrays.sort(roots);
                            for (int i = 0; i < roots.length; i++) {
                                try {
                                    System.out.println(roots[i]);
                                    SearchProgram searchProgram = new SearchProgram(roots[i], searchText);
                                } catch (Exception exception) {
                                }
                            }
    }

-----------------------------------------------------------------------------------

    class SearchProgram extends Thread {

            File fileDir;
            String fileName;

            public SearchProgram(File d, String n) {
                fileDir = d;
                fileName = n;
                this.start();
            }
            // this is a recursive file search function

            @Override
            public void run() {
                if (check) {
                    try {
                        search(fileDir, fileName);
                    } catch (Exception exception) {
                    }
                }
            }

            private void search(File dir, String name) {
                if (check) {
                    String dirPath = dir.getAbsolutePath();
                    if (dirPath.length() > 60) {
                        lblCurrentLocation.setText("\\\\.............." + dirPath.substring(60, dirPath.length()));
                    } else {
                        lblCurrentLocation.setText(dirPath);
                    }
                    if (dir.getName().toLowerCase().endsWith(name.toLowerCase())) {
                        tableModel.addRow(new Object[]{dir.getAbsolutePath()});
                    } else if (dir.isDirectory()) {
                        String[] children = dir.list();
                        for (int i = 0; i < children.length; i++) {
                            search(new File(dir, children[i]), name);
                        }
                    }
                }
            }
        }
请说明此代码有什么问题