I have just started programming and I am stuck while creating a basic File I/O program in java.
The use case: I want to check for a string in a file and append a string in the same line. E.G. The file contents are as follows :
hostname=localhost
port=192
So, I want my program to look for hostname string in the above file and replace localhost with what ever value I pass to it.
I am able to get the file and pass the contents to a temporary file , but not sure how to manipulate strings in the file. Any help is highly appreciated.
Here are two ways (basic without any error/exception handling and passing target and replacement as arguments) how you can do it.
If your file stores key/value pairs than the best way is to user
java.util.Properties