was 图片路径与存储 与tomcte不同
来源:互联网 发布:罗盘软件 编辑:程序博客网 时间:2024/05/16 05:56
public static File getClassFile(Class clazz){
URL path = clazz.getResource(clazz.getName().substring(
clazz.getName().lastIndexOf(".")+1)+".classs");
if(path == null){
String name = clazz.getName().replaceAll("[.]", "/");
path = clazz.getResource("/"+name+".class");
}
return new File(path.getFile());
}
/**
* 得到当前类的路径
* @param clazz
* @return
*/
public static String getClassFilePath(Class clazz){
try{
return java.net.URLDecoder.decode(getClassFile(clazz).getAbsolutePath(),"UTF-8");
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return "";
}
}
/**
* 取得当前类所在的ClassPath目录,比如tomcat下的classes路径
* @param clazz
* @return
*/
public static File getClassPathFile(Class clazz){
File file = getClassFile(clazz);
for(int i=0,count = clazz.getName().split("[.]").length; i<count; i++)
file = file.getParentFile();
if(file.getName().toUpperCase().endsWith(".JAR!")){
file = file.getParentFile();
}
return file;
}
/**
* 取得当前类所在的ClassPath路径
* @param clazz
* @return
*/
public static String getClassPath(Class clazz){
try{
return java.net.URLDecoder.decode(getClassPathFile(clazz).getAbsolutePath(),"UTF-8");
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
return "";
}
}
下附我写的代码调用类
String classPath=getClassPath(this.getClass());
//System.out.println(classPath);
String rooPath = classPath.replaceAll("WEB-INF/classes/","");
int j=rooPath.indexOf("WEB-INF");
String rootPath=rooPath.substring(0,j);
System.out.println(""+rootPath);
String filePath = "";
if("0".equals(vatType)){
filePath = rootPath+"/template/bill/zzszy_invoice.png";
}else{
filePath = rootPath+"/template/bill/zzspy_invoice.png";
}
System.out.println("模板路径"+filePath);
fileName = fileName+System.currentTimeMillis() + ".png";
String nF = rootPath+"/template/bill/outBill/" + fileName;
System.err.println("输出路径"+nF);
- was 图片路径与存储 与tomcte不同
- jetty处理请求路径与tomcat的不同,图片出不来
- 图片上传与存储
- 图片存储与读取
- TOMCAT与WAS运行时错误处理的不同
- 图片的存储与传递
- iOS 图片存储与NSData
- 图片加载与本地存储
- 图片存储与转换处理
- 存储过程的写法与不同
- 指针与数组不同的存储区域
- C++与matlab存储方式的不同
- Android 路径与存储设备相关
- 存储的控制器冗余与多路径
- delphi存储图片路径
- 图片存储路径
- 图片存储带沙盒路径
- 嵌入元素与图片路径问题
- Hadoop 解除 “Name node is in safe mode”
- Unable to execute dex: Multiple dex files define 解决方法
- 28.Android 十分方便的EasyRecyclerView
- 算法代码
- LeetCode8:String to Integer (atoi)
- was 图片路径与存储 与tomcte不同
- Magento 产品添加购物车时修改价格
- 浅谈Flag模式
- POJ3974 Palindrome(Manacher)
- 基于SIFT特征的图像配准(附Matlab源代码)
- leetcode之Sliding Window Maximum
- Genymotion常见问题的解决方法
- Chapter 2-InsertionSort
- 删除ScrollView中的Item时,要注意的一个问题