`
zeyuphoenix
  • 浏览: 56032 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

修改文件名

阅读更多
public static void main(String[] args) {

		String df = "/udd/itnms/file/123dd.dd.pdf";
		System.out.println(changeFileType(df));
		Properties d = new Properties();
	
		System.out.println(d.getProperty("key"));
		
		
		
		
		String ttt = "ff_d.22.2.txt";
		

		System.out.println(ttt.matches("^\\w+(\\.\\w+)*$"));
		System.out.println(ttt.getBytes().length);
		System.out.println(ttt.length());
		System.out.println(changeChar(ttt));
	}

	private static String changeFileType(String fileName) {

		int index = fileName.lastIndexOf("/");

		String signFileName = fileName.substring(index + 1);
		int indexType = signFileName.lastIndexOf(".");
		String addFileType = signFileName.substring(indexType + 1);

		if (addFileType.toLowerCase().equals("pdf")) {
			return fileName.substring(0, index + 1)
					+ signFileName.substring(0, indexType + 1) + "tif";
		}
		return null;
	}
	private static String changeChar(String oldFileName) {
		
		String changeName = oldFileName;
		
		int index = oldFileName.lastIndexOf("\\");
		String signFileName = oldFileName.substring(index + 1);
		int indexType = signFileName.lastIndexOf(".");
		String addFileType = signFileName.substring(indexType);
		
		String fileName = signFileName.substring(0, indexType);
		
		if (!fileName.matches("^\\w+(\\.\\w+)?$")) {
			
			fileName = getNowDate() + "_"  + "01";
			return oldFileName.substring(0, index + 1)
			+ fileName + addFileType;
		}
		
		return changeName;
	}
	
	/*
	 * 
	 */
	private static String getNowDate() {

		// 
		String nowDate = "";
		Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
		
        try {
			// 
			java.text.SimpleDateFormat simpleDateFormat = 
				new java.text.SimpleDateFormat("yyyyMMddHHmmssSSS");
			nowDate = simpleDateFormat.format(calendar.getTime());
        } catch (Exception e) {
        	return "";
        }
		return nowDate;
	}
	




	System.out.println(Thread.currentThread().getContextClassLoader()
				.getResource(""));
		System.out.println(TestPath.class.getClassLoader().getResource(""));
		System.out.println(ClassLoader.getSystemResource(""));
		System.out.println(TestPath.class.getResource(""));
		System.out.println(TestPath.class.getResource("/"));
		System.out.println(new File("").getAbsolutePath());
		System.out.println(System.getProperty("user.dir"));
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics