I'm working on an App for my company on Java
(Android
platform) and encountered an issue that I can't resolve.
Here's the thing: by reading a text file
I fill the content
string with the following:
String content = "";
content = buffReader.readLine(); buffReader.close();
This work pretty fine. The content
string is correctly filled with the file content. Every line data of this string is separated with a &
character, so I fill the lines
array like this:
String[] lines;
lines = content.split("&");
Again, no error here. Then, each field is separated with a :
character and again, I tried to fill the next strings in the same way:
String line; String[] data;
String data1 = ""; String data2 = ""; String data3 = ""; String data4 = "";
for (int i = 0; i < lines.length; i++){
line = lines[i];
data = line.split(":");
data1 = data[0];
data2 = data[1];
data3 = data[2];
data4 = data[3];
}
If the text is A:B:C:D
the code works fine. Even if the text is A:B::D
that's ok (and data3
becomes ""
like I intended). However, if the text is A:::
the code doens't work and shuts down the App. In this case, I can get data1 = data[0]
but for each of the other steps, the error shows up.
Does anyone knows what's going on?! Do I'm missing something? Thanks a lot.
EDIT:
If anyone could explain why the code works fine with A:B::D
text... I mean! It does have an empty filed, right?