几个代码片段-计算程序运行时间+获得当前目录+生成MD5

计算程序运行时间

	long startTime = System.currentTimeMillis();
	System.out.println("程序运行时间: " + (System.currentTimeMillis() - startTime) + "ms");

获得当前目录

	System.getProperty("user.dir")

生成MD5

	public String genMd5(final String input) {
		try {
			MessageDigest m = MessageDigest.getInstance("MD5");
			m.reset();
			m.update(input.getBytes());
			byte[] digest = m.digest();
			BigInteger bigInt = new BigInteger(1, digest);
			String hashtext = bigInt.toString(16);
			while (hashtext.length() < 32) {
				hashtext = "0" + hashtext;
			}
			return hashtext;
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return null;
	}
posted @ 2015-02-02 16:23  wardensky  阅读(234)  评论(0编辑  收藏  举报