Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9240023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:07:01+00:00 2026-06-18T08:07:01+00:00

I am able to obtain an InputStream to a resource in my WEB-INF folder

  • 0

I am able to obtain an InputStream to a resource in my WEB-INF folder like this :

    ExternalContext externalContext = facesContext.getExternalContext();
    InputStream in = externalContext.getResourceAsStream("/WEB-INF/config.xml");

Now I’d like to edit this file during runtime but I don’t know how to overwrite the file.
Is there a better way than creating a FileOutputStream to the absolute path ? And even if not I’d still need a way to obtain the absolute path of the file (the absolute path to the WEB-INF folder).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:07:02+00:00Added an answer on June 18, 2026 at 8:07 am

    As to the concrete question, you can get the absolute path to the file as follows:

    ExternalContext externalContext = facesContext.getExternalContext();
    String realPath = externalContext.getRealPath("/WEB-INF/config.xml");
    FileOutputStream output = new FileOutputStream(realPath);
    // ...
    

    As to the concrete funcitonal requirement, there are however 2 possible major problems:

    1. getRealPath() will return null when the container is configured to expand WAR file in memory instead of on disk. There’s then no means of a physical disk file system path. There’s no way to get a "file path" to the location in memory.

    2. Even if it returns a valid path, all changes made in the expanded WAR structure on the local disk file system will get lost whenever you redeploy the WAR, or even in some server configurations also when you just restart the server. The simple reason is that those changes are not contained in the original WAR file. You’d basically need to extract the WAR, make the change in there, pack the WAR again and trigger the redeploy of the server. This makes no sense during runtime.

    In other words, you’re looking for the solution in the wrong direction. You need to prepare a fixed local disk file system path and read/write from/to it instead. An alternative is to use a SQL database instead or very maybe java.util.prefs.preferences.

    See also:

    • Where to place and how to read configuration resource files in servlet based application?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a XML column which contains XML like this: <Set> <Element> <ID> 1
I'd like to be able to do something like this: #!/usr/bin/python if jira.user_has_permission('jsmith', 'JIRA-123'):
I would like to be able to obtain all the parameter values from the
I'm using .NET 3.5 and would like to be able to obtain every *
I want to be able to obtain the userid of a user in Active
not able to get this, can someone help for this LINQ query? select col1,
I can be able to save store address programmatically by $_address=nl2br('123\nTest',false); $config->saveConfig('general/store_information/address',$_address,'default',0); But the
I'm not being able to obtain an edit token for MediaWiki: Request POST /w/api.php
For build logging, I am able to obtain the current stream and last baseline
On the cart page I need to be able to obtain the parent SKU

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.