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?
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.
Joined: May 21, 2012
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.