How to read key=value file and how to split a comma-separated String?

Use java.util.Properties to read in the key=value file. Here is a Sun tutorial.

As for the CSV, you can read in all the lines and use String#split() to break each line into an array of values.


The Properties class will load your config file in the name=value format. Call the load method with a FileReader to the config file. The you can access any variable using the getProperty method.

Properties props = new Properties();
props.load(new FileReader(configFilePath));

String value = props.getProperty("name");

As for the CSV file, if all rows have the same number of values, you can read each line into an array using String.split(",") and assign it to a 2-d array. Then access a "column" by walking the 2-d array.

Tags:

Java