[英]Create folder in a relative path outside the project
How can i save a file to a relative path outside my project ? 如何将文件保存到项目外部的相对路径? So i can create a folder of resources on any computer the program runs on?
因此,我可以在运行该程序的任何计算机上创建资源文件夹?
I tried: 我试过了:
String folderPath=getClass().getClassLoader().getResource(".").getPath()+other stuff
to create a folder path where i save images. 创建一个我保存图像的文件夹路径。 It creates a me a folder like tomcat%20v7.0 where indeed my images are saved.
它会为我创建一个类似于tomcat%20v7.0的文件夹,在该文件夹中确实保存了我的图像。 I keep absolute path for every picture in my database and then load them in a jsp file.
我为数据库中的每张图片保留绝对路径,然后将它们加载到一个jsp文件中。 When running the app in eclipse, everything works fine.
在Eclipse中运行应用程序时,一切正常。 When trying to run in browser, photos aren't shown.
尝试在浏览器中运行时,不会显示照片。 Browser are installed on C: and tomcat/eclipse on E:
浏览器安装在C:上,tomcat / eclipse安装在E:上
public static List<String> getEndPoints() throws
MalformedObjectNameException,
NullPointerException, UnknownHostException,
AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objs = mbs.queryNames(new ObjectName(
"*:type=Connector,*"), Query.match(Query.attr("protocol"),
Query.value("HTTP/1.1")));
String hostname = InetAddress.getLocalHost().getHostName();
InetAddress[] addresses = InetAddress.getAllByName(hostname);
ArrayList<String> endPoints = new ArrayList<String>();
for (Iterator<ObjectName> i = objs.iterator(); i.hasNext();) {
ObjectName obj = i.next();
String scheme = mbs.getAttribute(obj, "scheme").toString();
String port = obj.getKeyProperty("port");
for (InetAddress addr : addresses) {
String host = addr.getHostAddress();
String ep = scheme + "://" + host + ":" + port;
endPoints.add(ep);
}
}
return endPoints;
}
//use above code to get path like "http://yourip:yourport/yourwebapppath"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.