G
gajo
OK, again I have troubles dealing with String. I have a field of the type
String which contains some text that is separated into lines at random
places, or in other words, the text contains \n\r (or \n in the case of
linux). I write this field into a file and there it looks ok, but when I
read it back I get the whole string in one line. So I figured I'd add a
separator at the end of each line. However, then I get an empty line after
each line! I'm using GZIP to pack the data, so perhaps that is causing this?
Btw. after each block of text I write an end-of-block string to know that
it's the end of that block.
Here's the explanation in code:
String notes = ""; // the result
String lin = ""; // used to read one line from the file
final String eob = "---$#-||-"; // end of block
lin = filein.readLine(); // I'm reading the 1st line
while (lin.compareTo(eob) != 0) {
notes += lin + System.getProperty("line.separator");
lin = filein.readLine();
if (lin == null) { break; } // this will never occur, but just in case
}
return notes;
//-------------
// filein is a BufferedReader
// I can't change that, don't ask why, and
// because of that this is how I read a file
filein = new BufferedReader(
new InputStreamReader(
new BufferedInputStream(
new GZIPInputStream(
new FileInputStream("testFile.gz"))))));
I figured I could erase one empty line after the reading-in is done, but I'm
not sure if this will happen in every case, on every computer. I'm thinking
it could be an anomaly for Windows files.
Anyway, I'm waiting for some suggestions
Gajo
String which contains some text that is separated into lines at random
places, or in other words, the text contains \n\r (or \n in the case of
linux). I write this field into a file and there it looks ok, but when I
read it back I get the whole string in one line. So I figured I'd add a
separator at the end of each line. However, then I get an empty line after
each line! I'm using GZIP to pack the data, so perhaps that is causing this?
Btw. after each block of text I write an end-of-block string to know that
it's the end of that block.
Here's the explanation in code:
String notes = ""; // the result
String lin = ""; // used to read one line from the file
final String eob = "---$#-||-"; // end of block
lin = filein.readLine(); // I'm reading the 1st line
while (lin.compareTo(eob) != 0) {
notes += lin + System.getProperty("line.separator");
lin = filein.readLine();
if (lin == null) { break; } // this will never occur, but just in case
}
return notes;
//-------------
// filein is a BufferedReader
// I can't change that, don't ask why, and
// because of that this is how I read a file
filein = new BufferedReader(
new InputStreamReader(
new BufferedInputStream(
new GZIPInputStream(
new FileInputStream("testFile.gz"))))));
I figured I could erase one empty line after the reading-in is done, but I'm
not sure if this will happen in every case, on every computer. I'm thinking
it could be an anomaly for Windows files.
Anyway, I'm waiting for some suggestions
Gajo