Re: Tomcat + java.io.FileNotFoundException

From: apatruduque (apatruduque_at_yahoo.es)
Date: 09/14/04


Date: Tue, 14 Sep 2004 09:07:33 +0200

Alex and Sudsy, thanks a lot for your suggestions. I'll try with resources,
since I have found a couple of places (one of them is the tomcat FAQ) in
which it is suggested to use resources to read files.

The problem is that the application was running smoothly using

File xyz= new File("[application-context-path]/fileB.xml");

However, after a controled shutdown and restart of the system (did not touch
any configuration file), I started getting the FileNotFound exceptions I
mentioned before, which is kind of "strange", and I cannot find an
explanation... may be the .class file being used was not corresponding to
the .java I had in the system.

The line before results in an error in catalina.out of the form:
 java.io.FileNotFoundException: file "/[application-context-path]/fileB.xml"
not found

which means that the File constructor is trying to access the / (root)
directory of the filesystem. I put file fileB.xml
in /[application-context-path]/fileB.xml (file system path) and the
exception desapeared. This is kind of strange for me, since I thought (and
probably wrong) that tomcat somehow wraps everything inside the context
path...

For these reasons, I'm trying to figure out if:
1- I was not accessing the file correctly, which apparently is the case
2- Is there a way to tell tomcat to add the real path somehow to the File
constructor

Thanks again,

Alfonso

> Application Server executes servlet and JSP in their own context (both
> different by the way).
> And patrh /xml/abc/xyz is added to this context root.
> It is better then read files not from file system but as resources like
> this:
> public String stringFromResource(String name) {
>
> String result = "";
> try {
> URL url = getClass().getResource(name);
> URLConnection conn = url.openConnection();
> InputStream istream = conn.getInputStream();
>
> BufferedReader in = new BufferedReader(new
> InputStreamReader(istream));
> String temp = "";
> while ((temp = in.readLine()) != null)
> result += temp + "\n";
> in.close();
> //System.out.println(result);
> } catch (Exception e) {
> System.out.println(e);
> }
> return result;
> }
>
> At least you know where is your resource root (exactly where is root for
> class loading).
>
> But if it's confusing for you I suggest to understand where are you in
> file system and then put your files to this place.
> Use regular java.io.File and run it INSIDE container! So you can
> understand where you are and read files later:
>
> java.io.File file=new java.io.File(".");
> or
> java.io.File fileRoot=new java.io.File("/");
> and then read files in your location and try to understand where it is
> eaxctly:
>
> out.println(fileRoor.getAbsolutePath() +" "+fileRoot.getCanonicalPath());
>
> or even this way:
> String [] list=fileRoot.list();
> if (list!=null) for (int i=0;i<list.length;i++) out println(list[i]);
>
> Alex Kizub.
 
 



Relevant Pages

  • Re: Two Ways To Identify An Idiot Web Developer
    ... Now as for "Computer Science" tell me one thing in ASP.NET/Web development ... > use the inherent capability of the file system to sort resources which by ... > attempting to retrieve a Favorite. ... > description of resources stored on the file system. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Two Ways To Identify An Idiot Web Developer
    ... use the inherent capability of the file system to sort resources which by ... use converse file naming in this context 'title text - personal identifier' ... description of resources stored on the file system. ... and it has been adopted as convention for good reason. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Treads in the new 6 core CPU from Intel
    ... Why do you think six cores are "fighting" for resources? ... implications of an asymmetric I/O bus structure on file system I/O? ... Why do you think the file I/O is not taking advantage of the File System Cache? ... What, in fact, do you mean by the phrase "database ...
    (microsoft.public.vc.mfc)
  • Re: FileSystemWatcher
    ... Let's just assume that you are invited to a party of your friend. ... system to notify about file system changes. ... doesn't have to poll every 1 second and ask the file system "How are ... It has the resources to do so and resources are being used. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Creating a File
    ... Thanks Alex. ... days scanning resources and have yet to find anything. ... their custom windows explorer solution source code ...
    (microsoft.public.access.modulesdaovba)