aspose file tools*
The moose likes Java in General and the fly likes Problem with java programing locating external files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem with java programing locating external files" Watch "Problem with java programing locating external files" New topic
Author

Problem with java programing locating external files

Edward Blom
Greenhorn

Joined: Jan 01, 2012
Posts: 4
I'm writing a tiny web server in java and Im using netbeans. I got a couple of external files and the function of the server is to display the files when I request them in the browser but I got a weird problem with the files. I've placed the files in the source package that contains the program and when I do that the function that checks if a file exists after you request it in the browser are able to find the file. But when the program send this filename into the function that sends the file to the browser the java program can't locate it. The strange part is that it works though if I place the file directly in the main folder but if I do that the part that checks if a file exist can't find it. Any idea how to solve this?
Antonio Principato
Greenhorn

Joined: May 21, 2012
Posts: 10
Are you doing this in an applet? If i remember correctly ( and i could definitely be wrong) you don't have access to local files using an applet for security purposes.
http://www.coderanch.com/how-to/java/HowCanAnAppletReadFilesOnTheLocalFileSystem
Edward Blom
Greenhorn

Joined: Jan 01, 2012
Posts: 4
No it's a regular java program. A solution I found is that I put the files both in the folder that keeps all the folders to my project and in the folder with the project name in the src folder but there has to be a way to solve this.
Antonio Principato
Greenhorn

Joined: May 21, 2012
Posts: 10
It may just be me misunderstanding but your first post seems a bit cryptic. So your program passes a filename to the server. The server checks to see if the file exists on the server and then sends the file to the program? If they are kept on the server are you looking for them in the correct directory? If you just pass a filename java will just check its src folder to see if it exists but not if you give it a full path. if all of the files are kept in the same place on the server you can just set the directory on the server side and add the file name to the end of the absolute path once the server receives it. That way when the server searches for the file it searches in the right folder for the filename given. I could be way off base just let me know if I'm on the right track.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with java programing locating external files