java相对路径(websphere):
代码如下:
int saveUrlIndex = ProfileModel.class.getResource("").toString().lastIndexOf("WEB-INF");
String saveUrl = ProfileModel.class.getResource("").toString().substring(0,saveUrlIndex).replace("file:/", "") + Constants.IMG_SAVE_PATH;
其中:
ProfileModel: 是当前的类名
ProfileModel.class.getResource("") 是得到这个类编译后的地址.以file:/开头的地址
String saveUrl = ProfileModel.class.getResource("").toString().substring(0,saveUrlIndex)
是截取到"WEB-INF"的上级目录.
Constants.IMG_SAVE_PATH 是个常量,定义了跟"WEB-INF"同级的其他目录.
.........................................
tomcat跟wensphere不一样的只有用这个方法才可以.
以上代码只是笔记,为以后查看用.
代码如下:
int saveUrlIndex = ProfileModel.class.getResource("").toString().lastIndexOf("WEB-INF");
String saveUrl = ProfileModel.class.getResource("").toString().substring(0,saveUrlIndex).replace("file:/", "") + Constants.IMG_SAVE_PATH;
其中:
ProfileModel: 是当前的类名
ProfileModel.class.getResource("") 是得到这个类编译后的地址.以file:/开头的地址
String saveUrl = ProfileModel.class.getResource("").toString().substring(0,saveUrlIndex)
是截取到"WEB-INF"的上级目录.
Constants.IMG_SAVE_PATH 是个常量,定义了跟"WEB-INF"同级的其他目录.
.........................................
tomcat跟wensphere不一样的只有用这个方法才可以.
以上代码只是笔记,为以后查看用.