文件搜索器

来源:互联网 发布:淘宝上怎么找人工客服 编辑:程序博客网 时间:2024/06/07 13:02

有几天没写博客了,忘记了,今天想起来了,顺便把前面的内容补上吧。

文件搜索器就是界面加上文件夹的遍历操作。

public void sousuo(String path){File file = new File(path);if(file.exists()){if(file.isFile()){Filecount++;if( !guanjian.getText().equals("") ){if(file.getAbsolutePath().contains( guanjian.getText())){System.out.println(file.getAbsolutePath());shuchu.append(file.getAbsolutePath()+"\n");}}else{shuchu.append(file.getAbsolutePath()+"\n");}}else if(file.isDirectory()){Directorycount++;File[] files = file.listFiles();for(File f : files){sousuo(f.getAbsolutePath());}}}else{System.out.println("不存在文件");shuchu.append("不存在文件"+"\n");}}


   斌哥给我讲了文件的基本操作,有File类的基本文件操作方法如:isFile()、isDirectory()、getAbsolutePath()等方法,还有for(File f ; file)的遍历,期间也温习了界面的代码知识。

1 0