aspose file tools*
The moose likes Servlets and the fly likes file path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "file path" Watch "file path" New topic
Author

file path

Hong Yi
Greenhorn

Joined: Feb 13, 2008
Posts: 11
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?

Thanks
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30294
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

DEV or PROD environment in what sense? Is this a web application?
Hong Yi
Greenhorn

Joined: Feb 13, 2008
Posts: 11
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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
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 "/"

Thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It finds the file by looking on the classpath.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: file path