I'm using Netbeans IDE. For a school project I need to read an .ini-file, and get some specific information.
The reason I'm not using ini4j:
Example ini-file:
[Section]
Object1 5 m
number = 12
Object2 6 m
;Comment followed by white line
number = 1\
4
\
means the next command or white lines need to be ignored
So the last part of the ini file actually means: number = 14
My task: I need to store the oject names with the corresponding length (meters) and number into a single string like this: Object1 has length 1m and number 12
My problem:
I use a scanner with delimiter //Z
to store the whole file into a single String.
This works (if I print out the String it gives the example above).
I've tried this code:
String file = file.replaceAll("(\\.)(\\\\)(\\n*)(\\.)","");
If I try to only remove the newlines:
String file = file.replace("\n","");
System.out.println(file);
I get an empty output.
Thanks in advance !
You are on right way. But logic is on wrong place. You actually need \n for your logic to recognize new value in your ini file.
I would suggest that you do not read entire file to the string. Why? You will still work with line from file one by one. Now you read whole file to string then split to single strings to analyze. Why not just read file with scanner line by line and analyze these lines as they come?
And when you work with individual line then simply skip empty ones. And it solves your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With