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 8813427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:50:52+00:00 2026-06-14T03:50:52+00:00

I want to write into a *.properties file. Thats my code how I do

  • 0

I want to write into a *.properties file. Thats my code how I do this:

    properties = loadProperties("user.properties");//loads the properties file
    properties.setProperty(username, password);
        try {
                properties.store(new FileOutputStream("user.properties"), null);
                System.out.println("Wrote to propteries file!" + username + " " + password);

I do not get an exception, but I also do not get the output written into the file.

Here is also my file-structure:

enter image description here

I appreciate your answer!!!

UPDATE

I load my properties file with:

    InputStream in = ClassLoader.getSystemResourceAsStream(filename);

My question is, how to load it from a specific path?

Here is my “new” File Structure:

enter image description here

  • 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-14T03:50:53+00:00Added an answer on June 14, 2026 at 3:50 am

    Here is my testing code:

    @Test
    public void fileTest() throws FileNotFoundException, IOException {
    
        File file = null;
    
        Properties props = new Properties();
    
        props.setProperty("Hello", "World");
    
        URL url = Thread.currentThread().getContextClassLoader()
                .getResource("exceptions/user.properties");
    
        try {
            file = new File(url.toURI().getPath());
    
            assertTrue(file.exists());
        } catch (URISyntaxException e) {
    
            e.printStackTrace();
        }
    
        props.store(new FileOutputStream(file), "OMG, It werks!");
    
    }
    

    It does creates and rewrites a file in my target/classes/exceptions directory (in a maven/eclipse proyect) so I guess it really works, but of course that is not tested in a JAR file.

    Here is the file:

    #OMG, It werks!
    #Sat Nov 10 08:32:44 CST 2012
    Hello=World
    

    Also, check this question: How can i save a file to the class path

    So maybe what you want to do never will work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a .xml file using the following code into the App_Data/posts.
i have an char array b[20] which i want to write into a file
I want to write data into the file in binary form. I was trying
I want write a little code analyzer which parses nested structures and translates into
i want simultaneously read and write data into file. Can i use StreamReader and
I want to write the bulk of data into xml file ,the data coming
I am using ofstream() to write data into file, i want the program to
In Linux environment, I want to create a file and write text into it:
I want to load this simple something into my Editor: Write:-repeat,write(hi),nl,fail. So that it
im using log4j to write into a file with the following properties file :

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.