您的位置:首页 > 其它

获取src下文件路径(本地+服务器)

2017-04-18 10:25 337 查看
        //获取src下文件所在本地路径

public static String getFilePath2(String _fileName) {
File directory = new File("");// 参数为空
String _filePath = null;
try {
_filePath = directory.getCanonicalPath();
} catch (IOException e) {
e.printStackTrace();
}
return _filePath + "\\src\\" + _fileName;
}

 //获取src下文下所在服务器路径
public static String getFilePath(String _fileName) {
// String
// _filePath=request.getSession().getServletContext().getRealPath("/");
// String _url= _filePath+"WEB-INF//classes//"+"123789.pfx";
String url = new ShanghaiYHUtil().getClass().getClassLoader().getResource("/").toString();
url = (url.substring(5, url.length()) + _fileName);
logger.info("********************************" + url);
return url;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: