If you can use x = y instead of x, y, you can use the Properties class.
If you need to have x, y, look at java.util.Scanner , you can set a separator to use as a separator (javadoc shows examples of this).
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; class Main { public static void main(final String[] argv) { final File file; file = new File(argv[0]); try { final Scanner scanner; scanner = new Scanner(file); while(scanner.hasNextLine()) { if(scanner.hasNext(".*,")) { String key; final String value; key = scanner.next(".*,").trim(); if(!(scanner.hasNext())) {
and property versions (easier to parse because they are not)
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import java.util.Properties; class Main { public static void main(final String[] argv) { Reader reader; reader = null; try { final Properties properties; reader = new BufferedReader( new FileReader(argv[0])); properties = new Properties(); properties.load(reader); System.out.println(properties); } catch(final IOException ex) { ex.printStackTrace(); } finally { if(reader != null) { try { reader.close(); } catch(final IOException ex) { ex.printStackTrace(); } } } } }
source share