• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with java programing locating external files

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
https://coderanch.com/how-to/java/HowCanAnAppletReadFilesOnTheLocalFileSystem
 
Edward Blom
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic