取得程序的物理路径 private String getClassPath() { String strClassName = getClass().getName(); String strPackageName = ""; if(getClass().getPackage() != null) { strPackageName = getClass().getPackage().getName(); } String strClassFileName = ""; if(!"".equals(strPackageName)) { strClassFileName = strClassName.substring(strPackageName.length() + 1,strClassName.length()); } else { strClassFileName = strClassName; } URL url = null; url = getClass().getResource(strClassFileName + ".class"); String strURL = url.toString(); strURL = strURL.substring(strURL.indexOf('/') + 1,strURL.indexOf("/WEB-INF/")); strURL = strURL.replaceAll("%20"," "); //防止路径中存在空格 return strURL; }