• 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

Best way for a Servlet to access file

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using Tomcat 4.1 and Win 2003, I had a Servlet app that read 15,000 integers from a data file on the local Server hard drive. With Tomcat 7 and Win 2012, my Servlet gets error messages (java.io.FileNotFoundException) trying to read from the local drive. What would be the best way to access data on the Server with a Servlet?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are getting a file-not-found exception, then the path to the file is wrong, or the file does not exist. Your next step is to determine which.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. Tomcat 4? Might be time to think of an upgrade.
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you'll post the code of the class that does the file i/o we can probably spot the path problem. The file i/o shouldn't be in the servlet, but we'll deal with that later.

Make sure the file does actually exist. It's possible that whatever routine creates that file has failed.
 
Eric Racin
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I can post the code. I read in 2 arrays that are both 5x6: so the number of elements is 6x6x6x6x6 = 7,776. I thought if I included the arrays in the .java file itself, I wouldn't have to worry about the issues with reading from files.
I access the local C: drive file with
I get the error msg

Error: java.io.FileNotFoundException (the system cannot find the file specified)


Remember that for 5 years I never had a problem: I suspect Win 2012 is not giving permission rights for Tomcat 7 to read a file on the local host.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you check that the file exists? If it does, are the permissions correct?
 
J. Kevin Robbins
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Racin wrote:
Remember that for 5 years I never had a problem: I suspect Win 2012 is not giving permission rights for Tomcat 7 to read a file on the local host.



I suspect this is correct. But is it Tomcat 4 or 7? You've mentioned both.

As Bear says, make sure the file exists and that the account running the web application (tomcat, probably) has the necessary file permissions. The file permissions have to be granted to the account that is running the Tomcat service.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

J. Kevin Robbins wrote:As Bear says, make sure the file exists and that the account running the web application (tomcat, probably) has the necessary file permissions. The file permissions have to be granted to the account that is running the Tomcat service.



And as a follow-up to that statement, you must be running the Tomcat service under an actual account and not under "Local System Account" or some other pseudo-account. Even if you grant permissions for the file to "Everybody" that still won't allow those pseudo-accounts to access the file.
 
reply
    Bookmark Topic Watch Topic
  • New Topic