Guys, Need your help on the below. Have a simple application that allows the user to register on the website. Have a properties file that i need to store the username & password with which the user would register.
The code is as below :- --------------------------------------- Properties properties.put(userId, userPassword); String fileName = this.getClass().getClassLoader().getResource("resources/registeredUser.properties").getFile();
I do not see the new User Id's and Passwords in the Properties file nor do i see any exceptions.
Thanks in advance, -Navi
Joined: Feb 05, 2003
The code itself seems ok (it does not compile, but I assume it's a copy/paste error)
Are you sure that you are looking at the correct properties file to verify the result? For example when you would be using Eclipse, and the file is in a source folder, the modified file is in the (hidden) bin folder and not in your source folder.
I think the problem is in your location. The getResource() method looks relative to your classpath, whereas the file is written relative to the current directory. If these are not the same you won't overwrite the file but create another one.
Please note that this approach is definitely not thread-safe. If two users register at the same time, both will try to write to the same file at the same time, with different contents.