Results 1 to 2 of 2
- 05-04-2009, 04:05 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 18
- Rep Power
- 0
working directory in web application
I have my Java project, say in C:\User\Workspace\myApplication
And there’s an xml file in that folder: C:\User\Workspace\myApplication\myXML.xml
And in my java program, I will take that xml file to retrieve information. So, I need to call it from my program. And now I am loading that file like:
File xmlfile = new File(“C:\\User\\Workspace\\myApplication\\myXML.xm l”)
And I know that it’s not a good way to load a file using directly the absolute path. So, I try to call it from my program dynamically. Here, my program is web application. And I use Tomcat.
First, I tried this way:
File directory = new File(“.”);
String loc = directory.getCanonicalPath();
File xmlfile = new File(loc + “myXML.xml”);
And, second I tried using: System.getProperty(“user.dir”);
Both first and second way give me the same result. When I tried to test those methods as Java application, they both gave me the path : C: \User\Workspace\myApplication
But when I tried to put it in my program which accepts input from JSP and run on server, then the result path is: C:\Eclipse. So, there’s an error that the system cannot find the file.
Why it cannot find the actual path?
And how can I do it to load that xml file into my Java program.
Any reply would be greatly appreciated.
- 05-04-2009, 07:45 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
If you want to "get" a file on the client, forget this entirely and Google "Java File Upload". If you want a file on the server, place it somewhere in the web application directory and start with getResource/getResourceAsStream/getContext/getContextPath/getRealPath calls of ServletContext.
Java EE 5
Similar Threads
-
contentType="application/vnd.ms-excel" Not Working
By JordanParfitt in forum Advanced JavaReplies: 1Last Post: 02-06-2009, 03:16 PM -
JNLP - Swing application compiled in jdk1.5 not working in jdk1.6
By mahendra.athneria in forum AWT / SwingReplies: 4Last Post: 01-20-2009, 08:27 PM -
Static function to get current working directory
By Java Tip in forum Java TipReplies: 1Last Post: 06-23-2008, 02:13 AM -
Java mail problem(working in intranet,but not working in iternet)
By sundarjothi in forum Advanced JavaReplies: 8Last Post: 05-28-2008, 07:00 AM -
How to get the current working directory in EJB?
By sathish_2111 in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 07-19-2007, 04:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks