Joshua Deshazer Joshua Deshazer - 1 year ago 139
Ini Question

parsing Pipe Ini with Java

I have an ini file that has some data that is separated by pipe. I want to read in the file and then set key,value to a string or something with java.

I was using ini4j but everywhere I look in order to parse the ini file you need to have something with sections my file does not have it the data looks like this

4800-722|4800 Logics
4800-723|4800 Logics
4800-743|4900 Logics
4900-745|4900 Logics
4900-746|4900 Logics
4900-786|4900 Logics
4800-C41|4900 Controllers
4800-C42|4900 Controllers

I want to take this and for example put the first one as a key then the second as a value like hashmap. The problem I am having I cant find how to parse this ini file like that everything I see you should use sections and get something from the sections. I cant move this to a text file this is a file that lives on the server and I have to use it. Any help would be appreciated I just have this so far

Wini ini;
try {
ini = new Wini(new File("C:/toolbox/settings.ini"));

} catch (InvalidFileFormatException e) {
System.out.println("Invalid file format.");
} catch (IOException e) {
System.out.println("Problem reading file.");

Answer Source

I just read this as a text file and was able to parse out what I needed my code is below thank you UnholySheep.

  public static void LoadEtlData(String[] args) throws IOException {
    String file_name = "C:/toolbox/troux_etl.ini"; 
    ArrayList<String> records = new ArrayList<String>(); 

    try {
        BufferedReader reader = new BufferedReader(new FileReader(file_name)); 
        String line; 
        while ((line = reader.readLine()) != null){

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download