- java文件搜索
- public void getDir(String strPath) throws Exception
- {
- try
- {
- File f=new File(strPath);
- if(f.isDirectory())
- {
- File[] fList=f.listFiles();
- for(int j=0;j<fList.length;j++)
- {
- if(fList[j].isDirectory())
- {
- System.out.println(fList[j].getPath());
- getDir(fList[j].getPath()); //在getDir函数里面又调用了getDir函数本身
- }
- }
- for(int j=0;j<fList.length;j++)
- {
- if(fList[j].isFile())
- {
- System.out.println(fList[j].getPath());//把这话换成你要处理的语句.比如 fList[j].substring(fList[j].length-3,3)=="txt"
- }
- }
- }
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- java 文件与文件夹拷贝
- File fileOld = new File(pathOld);
- File fileNew = new File(pathNew);
- if(fileOld.exists()){
- try {
- FileInputStream fis = new FileInputStream(fileOld);
- FileOutputStream fos = new FileOutputStream(fileNew);
- int read = 0;
- while ((read = fis.read()) != -1) {
- fos.write(read);
- fos.flush();
- }
- fos.close();
- fis.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- java文件重命名
- File file = new File("D:\\123.txt");
- if(file.exists()) {
- file.renameTo(new File("D:\\1234.txt"));
- }
java 文件与文件夹拷贝、重命名、文件搜索
最新推荐文章于 2024-04-25 16:10:18 发布