Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

Updating an ini file in a servlet

Thread view: 
vincente13@gmail.com - 06 Dec 2006 07:31 GMT
Hi all,

I have this servlet that when it is called, it would update a
config(.ini) file that is bundled with it together as a webapp.

Users are able to enter a new username via a form and the servlet will
be called when the user press the submit button.

However the test.ini is not updated, any ideas to solve this issues?

FileInputStream in = new FileInputStream("test.ini");
Properties p = new Properties();
p.load(in);
p.setProperty("MailUserName", +userName);
p.store(new FileOutputStream("test.ini"), null);

There isn't any issues if an absolute path is given but i would need to
update the test.ini that is within the webapp.

p.store(new FileOutputStream("c:\\test.ini"), null);
       
Appreciate any advice
Simon Brooke - 06 Dec 2006 17:00 GMT
> Hi all,
>
[quoted text clipped - 5 lines]
>
> However the test.ini is not updated, any ideas to solve this issues?

You cannot write into a webapp which does not get unpacked. If you are
using Tomcat, check that unpackWARs="true" in the server.xml file.

You can get a directory you can write to within your webapp using the
following:

 uploadDirPath =
   config.getServletContext(  ).getInitParameter( "upload_dir_path" );

 File uploadDir =
       new File( getServletContext(  ).getRealPath( uploadDirPath ) );

   if ( !uploadDir.isDirectory(  ) || !uploadDir.canWrite(  ) )
   {
       throw new UnavailableException(
                       "Cannot write to upload directory " +
                       uploadDirPath );
   }

Signature

simon@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/

       'graveyards are full of indispensable people'



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.