• 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

Having problems reading a file from servlet in Windows XP with Tomcat

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am running into a situation where I am not sure where to go next and things are driving me crazy. I have a servlet in Tomcat that has a startup parameter that tells me the location of my properties file. I can retrieve this parameter and SOP it and looks fine.
I then try and read the file into the properties and I get an error stating that the file was not found. I have checked the file and it is there and it is in a simple directory called c:\\test, so the 8.3 is not a problem. I have written and re-written this many different ways and all say the same thing "File not found"
I can however take the same directory and create a file there, and that works. I really think it has to do with XP but want to see if anyone can help.
I will keep up to date on this through out the day and reply if I can. Thanks in advance for the help
[ September 18, 2003: Message edited by: Thad Henry ]
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, could you show us the code where you are trying to load the file?
Also, is there a reason you have this properties file on the root of your C drive?
What I have seen done, and what I tested and it worked, is putting a properties file in the WEB-INF and then using the ServletContext to load the file. This is really easy and it puts your properties file in a protected space.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When file reading gives me a problem I like to create a java.io.File object and do a System.out.println( theFile.getAbsolutePath() );
This has revealed some odd naming problems.
Also, are you sure the file security clearances are ok?
Bill
 
Thad Henry
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everyone,
At this moment I don't have the code that I wrote ( I'm at work and code is at home), I will post as soon as I get home. However, I can answer a couple of questions. I put the file on the C drive to try an elminate any 8.3 issues (if there were any). I initially had some code that used the ServletContext to determine the file name and that is when the problems started. I had the file under the app folder in Tomcat in its own properties directory, and it could not find it, so I moved it to the root directory to help eliminate problems. This however did not help either.
I have done this type of code before but never on an XP machine, and I am wondering if there is some kind of security problem. My next step when I get home tonight is to transfer the code to a 98 machine running Tomcat and see if the problem still exists. I would have done it last night but it was 1:00am in the morning and work comes early.
William if you could let me know what security issues you have seen I would appreciate it. I am really new to XP and appreciate the help. Again thanks to all for the replies
 
Thad Henry
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everyone,
I found the code that I originally started out with, it was from the Log4J manual:
public void init() {
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
// if the log4j-init-file is not set, then no point in trying
if(file != null) {
PropertyConfigurator.configure(prefix+file);
}
}
I had the file in the WEB-INF/classes directory and it too could not find it. Just wanted to post an update.
 
Thad Henry
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everyone,
Here is the code that I am using and the output from the stdout. I have verified that the file is where it says it should be. Any help is greatly appreciated.
Code:
public void init() {
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
Properties props = new Properties();
try {
System.out.println("File path is --> " + prefix + file);
FileInputStream inputStream = new FileInputStream(prefix + file);
props.load(inputStream);
System.out.println("log4j.rootLogger is --> " + props.get("log4j.rootLogger"));
} catch (Exception e) {
System.out.println("Exception in props load " + e);
}
System.out.println("The log config file is --> " + file);
try {
// if the log4j-init-file is not set, then no point in trying
if (file != null) {
//PropertyConfigurator.configure(props);
}
} catch (Exception e) {
System.out.println("Exception on property configurator " + e);
}

Output:
Bootstrap: Create Catalina server
Bootstrap: Starting service
Starting service Tomcat-Standalone
Apache Tomcat/4.1.27
File path is --> C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\marmon\\\properties\\log4j.lcf
Exception in props load java.io.FileNotFoundException: C:\Program Files\Apache Group\Tomcat 4.1\webapps\ROOT\marmon\properties\log4j.lcf (The system cannot find the file specified)
The log config file is --> \\properties\\log4j.lcf
Bootstrap: Service started
 
Thad Henry
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Everyone,
Just wanted to let you all know that I found the problem. XP was adding a .TXT to each of my files and I didn't know it. When I moved the App over to 98 it showed in Explorer. I have now changed my XP to show all extensions. I would like to thank everyone for their time and understanding.
Thad
 
Paper beats rock. Scissors beats tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic