1

我在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);
                        }
                    }
                }
            }
        }

请建议这段代码有什么问题

4

0 回答 0