2008-03-24

获取工程路径(jar和普通文件结构通用) -- java

关键字: jar 路径 工程路径

 

/**
	 * 获取工程所在目录
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	private static String getProjectPath() throws UnsupportedEncodingException{
		URL url = [ThisClass].class.getProtectionDomain().getCodeSource().getLocation();
		String filePath = URLDecoder.decode(url.getPath(), "UTF-8");
		if(filePath.endsWith(".jar"))
			filePath = filePath.substring(0, filePath.lastIndexOf("/") + 1);
		return filePath;
	}
 

 

评论
发表评论

您还没有登录,请登录后发表评论

JoeDanny
搜索本博客
最近加入圈子
存档
最新评论