Hi,
I have a question about file location. when I give physical location (for example c:\test\file.txt) for my file path on my local machine. The file can be found and read.
My question is: does it work in DEV or PROD environment? if not, what is the correct path I should give?
Hong Yi wrote:My question is: does it work in DEV or PROD environment?
If you have your files stored in a known location like /mine/properties, this does work. An alternative is to add the directory to your classpath and let Java read them as a resource. If your files are under a server, you have to do this.
DEV or PROD environment in what sense? Is this a web application?
Hong Yi
Greenhorn
Joined: Feb 13, 2008
Posts: 11
posted
0
DEV or PROD is deployed environment. The application is web application. and static files like html will be deployed to web server and dynamic files like jsp will be deployed to application sever.
It depends on how you want to do it, then. Direct client access, no. You'd have to read via absolute path or as Jeanne mentioned and write the response.
Hong Yi
Greenhorn
Joined: Feb 13, 2008
Posts: 11
posted
0
Thanks David and Jeanne. I use the following code:
InputStream is = getClass().getClassLoader().getResourceAsInputStream("fileName") ;
it works on localhost and DEV environment without giving a physical path of the file.
but I still have two questions:
1> how does it find the file?
2>do I need to provide "/" before the fileName like "/fileName"? and why does it work without "/"