Reading a UE3 .ini file by using Java's BufferedReader reads lesser number of lines than present in input file

34 Views Asked by At

Problem

I'm trying to read the configuration file for Gearbox Software's 2012 Video game "Borderlands 2".

  • The problem i'm facing is that the input file i'm reading from is of 2,245 lines and 77,344 length whereas the number of values in the map in which i'm reading this file into is only 859 lines and 31,786 length.

  • It is not that the stream is getting closed prematurely because manual checking revealed that the last lines are there, it's the random lines in the middle that are missing.

  • i even tried Files.readAllLines() but i cannot seem to read more than 859 lines from the input file.

  • When i output this map to a new file using FileWriter, the number of lines is 860, with one extra blank line added in the middle of the program

  • I have checked the other threads for reading .ini files. I will use ini4j or regular expressions once i figure out what i'm doing wrong here.

My Map object

Map <String,String>config_vals=new LinkedHashMap<>();
   

My Objects for Input

InputStream IS= new FileInputStream("C:\\Users\\V\\BC\\WillowEngine.ini");
Reader R=new InputStreamReader(IS);
BufferedReader BFR=new BufferedReader(R);

Loop for reading the contents of the file

while((temp=BFR.readLine())!=null)
 {
    if(temp.indexOf("=")==-1)             //if not a key-value pair, put whitespace as value
     config_vals.put(temp,"");  
    else
    {
     int separator=temp.indexOf("=");     //separating a k-v pair from a file into map entry     
     config_vals.put(temp.substring(0,separator),temp.substring(separator+1,temp.length()));
    }
}
BFR.close();
System.out.println(config_vals.size());  // prints 859

I worked an hour or so yesterday and i'm unable to figure out what i'm doing wrong here.

0

There are 0 best solutions below