You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by chuanjiang lo <lo...@gmail.com> on 2006/12/06 07:51:42 UTC

Updating a config(.ini) file in Action class

Hi all,

I have this web app that allows user to change the config (.ini) file via a
form. When the user submits the form, it goes into the action class and the
action class is supposed to update the ini file accordingly.

The ini file is lumped together with my action class.

FileInputStream in = new FileInputStream("test.ini");
Properties p = new Properties();
p.load(in);
p.setProperty("User name", username);
p.setProperty("Password", password);
p.store(new FileOutputStream("test.ini"), null);

However the ini file is not updated in the webapp directory.
if i change p.store(new FileOutputStream("test.ini"), null); to p.store(new
FileOutputStream("c:\\test.ini"), null);
The test.ini will appear in c:\

How should i go abt updating the ini file that is together with the webapp?

Appreciate any advice

Re: Updating a config(.ini) file in Action class

Posted by chuanjiang lo <lo...@gmail.com>.
On 12/6/06, Venkata Phani Kumar <ve...@ocimumbio.com> wrote:
>
> Hi,
> You can get any resource path wich is under context path using
> ServeletContext.getRealPath().
> The usage of this method is here,
>                 String iniFilePath =
> request.getSession().getServletContext().getRealPath("test.ini");
>
> you can use the 'iniFilePath' to instatiate FileOutStream, and do what
> ever
> you want.



that helps a lot
Thanks and appreciate that! :)

Re: Updating a config(.ini) file in Action class

Posted by Venkata Phani Kumar <ve...@ocimumbio.com>.
Hi,
You can get any resource path wich is under context path using
ServeletContext.getRealPath().
The usage of this method is here,
                String iniFilePath =
request.getSession().getServletContext().getRealPath("test.ini");

you can use the 'iniFilePath' to instatiate FileOutStream, and do what ever
you want.

Hope this will help you out....

Regards,
Venkata Phanikumar. G
----- Original Message ----- 
From: "chuanjiang lo" <lo...@gmail.com>
To: <us...@struts.apache.org>
Sent: Wednesday, December 06, 2006 12:21 PM
Subject: Updating a config(.ini) file in Action class


> Hi all,
>
> I have this web app that allows user to change the config (.ini) file via
a
> form. When the user submits the form, it goes into the action class and
the
> action class is supposed to update the ini file accordingly.
>
> The ini file is lumped together with my action class.
>
> FileInputStream in = new FileInputStream("test.ini");
> Properties p = new Properties();
> p.load(in);
> p.setProperty("User name", username);
> p.setProperty("Password", password);
> p.store(new FileOutputStream("test.ini"), null);
>
> However the ini file is not updated in the webapp directory.
> if i change p.store(new FileOutputStream("test.ini"), null); to
p.store(new
> FileOutputStream("c:\\test.ini"), null);
> The test.ini will appear in c:\
>
> How should i go abt updating the ini file that is together with the
webapp?
>
> Appreciate any advice
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org