You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Chandana Napagoda <cn...@gmail.com> on 2010/08/04 12:28:13 UTC

Access XML file inside the Java File

Hi All,


I have Domain class it need to read file and need to return File object.
When I'm getting my file object. My domain class always try to access in Bin
("D:\Share\apache-tomcat-6.0.20\bin\connections.xml")

It it possible to access read file inside the War file?


Thanks,
Chandana

RE: Access XML file inside the Java File

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Chandana Napagoda [mailto:cnapagoda@gmail.com]
> Subject: Access XML file inside the Java File
> 
> I have Domain class it need to read file and need to return 
> File object.

Bad design.  When running inside an app server, there's no guarantee that you have any access to the underlying file system, other than a container-provided scratch area.  Much better to use ServletContext.getResourceAsStream().

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


Re: Access XML file inside the Java File

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chandra,

On 8/4/2010 6:28 AM, Chandana Napagoda wrote:
> I have Domain class it need to read file and need to return File object.
> When I'm getting my file object. My domain class always try to access in Bin
> ("D:\Share\apache-tomcat-6.0.20\bin\connections.xml")

Maybe you have the path wrong. Maybe not. What does your code look like?

That's kind of rhetorical, since I know it looks like this:

InputStream in = new FileInputStream("connections.xml");
...

...but post your code, anyway.

> It it possible to access read file inside the War file?

Yes. Use the Servlet API to get access to your webapp's resources
instead of trying to read the disk directly. Hint: look at methods in
the ServletContext class.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxZbvgACgkQ9CaO5/Lv0PAWcACgt9NBV9Y4Ljhc7HLDyyHJ6ksX
xJ8AoLjWH1T02loHtAAW0zOyrwKzPGp2
=ssJ1
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org