# How to read a file?

**URL:** <https://techcommunity.softwareag.com/t/how-to-read-a-file/57627>\
**Category:** Forum\
**Tags:** Former-Crossvision-Products, Application-Composer\
**Created:** [March 30, 2007, 7:38pm UTC](https://techcommunity.softwareag.com/t/how-to-read-a-file/57627 "2007-03-30T19:38:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![consros](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@consros](https://techcommunity.softwareag.com/u/consros)\
**Post date:** [March 30, 2007, 7:38pm UTC](https://techcommunity.softwareag.com/t/how-to-read-a-file/57627/1 "2007-03-30T19:38:59Z")

</div>

Hello,

we have an own settings file and we want to read it, what is the right/best way to do this? We have tried simply with java.io.File(findCISDirectory()+“name.ext”) but this seems to be wrong, isn’t it?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Bjoern\_Mueller](https://avatars.discourse-cdn.com/v4/letter/b/e9bcb4/32.png) [@Bjoern\_Mueller](https://techcommunity.softwareag.com/u/Bjoern_Mueller)\
**Post date:** [March 30, 2007, 7:51pm UTC](https://techcommunity.softwareag.com/t/how-to-read-a-file/57627/2 "2007-03-30T19:51:42Z")

</div>

Hi,

there are two ways:

(1) through the file system. Via the “Params.getApplicationDircectoryName()” you can get the directory path into the webapplication and then read via file IO. BUT: this is not recommended! It is only supported with servlet engines supporting file access - e.g. JBoss will have problems.

(2) through the servlet context. The servlet context provides the possibility to access all files of the web application. We hava a wrapper class for accessing the servlet context which is WebResourceReader. You pass as parameter the path within your web applciation (e.g. “WEB-INF/web.xml”) and receive back the content.

For “serious” J2EE implementation only (2) is an option! (1) must only be used in case you are sure forever to live in a Tomcat environment. Only (2) still works with cluster scenarios!

Hope this helps…

Bj

---

<div class="post-metadata">

**Author:** ![consros](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@consros](https://techcommunity.softwareag.com/u/consros)\
**Post date:** [March 30, 2007, 7:55pm UTC](https://techcommunity.softwareag.com/t/how-to-read-a-file/57627/3 "2007-03-30T19:55:33Z")

</div>

Thanks! Second way seems to be exactly what we’ve bin looking for!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:38pm UTC](https://techcommunity.softwareag.com/t/how-to-read-a-file/57627/4 "2021-04-02T14:38:46Z")

</div>


