Analyzing a line of a text file
Hi,
I'm quite new to Java, but I've already completed an Android project. I now started on a Java project, but an error has been occuring for a long time. I have tried to find the reason, but couldn't succeed. As my last resource I would like to ask you if you know what might go wrong.
I basically have a text file, consisting out of many X and Y points enclosed by square brackets. A name can be added behind the points, but is not always the case. A fragment:
[50599800][526496200][50595100][526503000]Hogerbeetsstraat
[50607053][526488901][50607585][526488173][50601960][526486652][50601426][526487378][50607053][526488901]
As you've probably guessed, I want to read the numbers and additional names into my application. To do this, I've written this relatively small piece of code:
Code:
FileReader file = new FileReader("C:\\maps2\\"+i+"\\"+i2+".mada");
BufferedReader reader = new BufferedReader(file);
while (reader.ready())
{
line = reader.readLine();
line2 = line;
ways[ways_length] = new double[line.replaceAll("[^\\[]", "").length()];
count = 0;
while (line.contains("["))
{
begin = line.indexOf("[")+1;
end = line.indexOf("]");
if (line.substring(begin, end).equals("50631700"))
{
System.out.println(count);
System.exit(0);
}
ways[ways_length][count] = Double.parseDouble(line.substring(begin, end))/lonlat_multiplier;
line = line.replace(line.substring(begin-1, end+1), "");
count ++;
}
//System.out.println(ways[ways_length].length);
if (line.length() > 0)
{
ways_name[ways_length] = line;
if (ways_name[ways_length].equals("Metselaarsstraat"))
{
System.out.println("<"+ways_length+"|"+ways[ways_length][2]+"|"+ways[ways_length][3]);
System.out.println(line2);
System.out.println(ways[ways_length].length);
}
}
ways_length ++;
}
file.close();
reader.close();
The initialization of the variables used has been done before.
The problem:
Everything's read correctly, and even displayed correctly (the code for that, I haven't shown). However, at a few lines (each run the same ones) it looks like count remains the same. In other words, the line "count ++;" isn't executed (so it looks).
This is one of the lines where it goes wrong:
[50631700][526503000][50631700][526502500][50634600][526498599][50635400][526498500][50639500][526499800][50636599][526504300]Metselaarsstraat
ways[ways_length][2] is first set to 5.0631700 then 1 loop later to 52.6502500 although this value should be assigned to ways[ways_length][3].
I can't figure out why this is happening and I'm hoping one of you could help me. If you need more information I'd be happy to add some more.
Regards,
Ragoune