> I need to create a file happy.txtin location
> D:/ProjFolder/SrcFolder/
> However i would like to use
> http://sitename/projectcontext/SrcFolder/ to create
> happy.txt
Do you wish to copy the file happy.txt from http://sitename/projectcontext/SrcFolder/ to D:/ProjFolder/SrcFolder/ ?
Can you explain it in more detail.
I have a servlet that creates a file happy.txt in the file system.
File happy = new File("D:/projectFolder/SrcFolder/happy.txt")
Instead I would like
File happy = new File(http://blah.com/srcFolder/happy.txt");
This way when i send the war file to someone else, it doest say FolderNotFoundException or something like that.
use
getServletContext().getRealPath(String path)
or
getServletContext().getResource(String path)
or
getServletContext().getResourceAsStream(String path)//try this
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/GenericServlet.html#getServletContext()
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html
Hope That Helps
getServletContext().getRealPath(String path)
or
getServletContext().getResource(String path)
or
getServletContext().getResourceAsStream(String path)//try this
Im sorry im unable to get the path through these methods. The trouble is that getServletContext().getRealPath("/") gives me the location of jboss tmp/deploy directory.
I just wrote a quick function today for transforming an absolutepath into a relative path (using Files). Don't know if this will be helpful, but here's the code
public static String getPathRelativeTo(String path, String relativeTo) {
if (!path.startsWith(relativeTo)) return null;
path = path.substring(relativeTo.length());
if (path.startsWith(File.separator)) path = path.substring(File.separator.length());
return path;
}