Check out Properties
. The Properties.load()
method has the ability to load a "key=value" formatted file into a map of keys -> values.
You can then access the data like theProperties.getProperty("path")
.
Note that you will have to trim leading/trailing double quotes off of the values if the file contains double quotes. For your situation, it is probably sufficient to simply remove all quotes, but it depends on your requirements.
Example: Loading the file:
Properties p = new Properties();
p.load(new FileInputStream("myfile.txt"));
String path = p.getProperty("path");
Example: Removing the double quotes (path
will contain, literally, "F://Files//Report.txt"
since that's what it is in the file):
path = path.replace("\"", "");
Note that getProperty()
returns null
if the property is not found, so you will want to prepare for that:
String path = p.getProperty("path");
if (path != null)
path = path.replace("\"", "");
Also note that this is a very naive way to remove double quotes (it will mercilessly remove all double quotes, not just ones at the beginning or end) but is probably sufficient for your needs.