zoukankan      html  css  js  c++  java
  • ttt

    //改目录下文件名的扩展名
    import java.io.File;
    public class re {
    	public static void main(String[] args){
    		File file = new File("D:\\tmep");
    		String pre = new String("sql");
    		String aft = new String("txt");
    		run(file,pre,aft);
    	}
    	public static void run(File f,String from,String to) {
    		
    		if (f.isFile())	renname(f,from,to);
    		else for (File a:f.listFiles())	run(a,from,to);
    		
    	}
    	public static String getSubname(File f) {
    		String[] names = f.getName().split("\\.");
    		if (names.length>1)		return names[names.length-1];
    		else return "";
    	}
    	public static String getname(File f ) {
    		String[] names = f.getName().split("\\.");
    		String filename = names[0];
    		for(int i=1;i<names.length-1;i++) {
    			filename = filename+"."+names[i];
    		}
    		return filename;
    	}
    	public static void renname(File renf,String from,String to) {
    			if (renf.isFile()&&(getSubname(renf).equalsIgnoreCase(from))) {
    			renf.renameTo(new File(getname(renf)+"."+to));
    			System.out.println(renf.getPath()+"->"+getname(renf)+"."+to);
    		}
    	}
    
    }
    
  • 相关阅读:
    最短路(Floyed、Dijkstra、Bellman-Ford、SPFA)
    查找技术
    简单线段树
    dfs
    bfs
    插件工具集合
    Web前端代码规范
    Javascript 判断手机横竖屏状态
    Git 笔记2
    git 笔记 1
  • 原文地址:https://www.cnblogs.com/qqjue/p/2609848.html
Copyright © 2011-2022 走看看