US-ASCII LF character
Hello all
I am reading a byte array and making a file out of it. the file is a csv file...which when opened in notepad shows CSV and when opened in excel shows values in their designated columns. The charSet we are using is US-ASCII. Everything is working fine but when we open this file in notepad...we are seeing a 'square' after every line. upon further researching i found out that it is the LF character (\n). So i made a new byte array and now i am passing everything EXCEPT the LF character
for (i = 0; i < csvBytes.length; i++)
{
if ((char)csvBytes[i]!='\n')
{
System.out.println("Putting character: " + (char)csvBytes[i]);
csvResults[i] = csvBytes[i];
}
else
System.out.println("At position " + i +" LF character was found: " + (char)csvBytes[i]);
Now after all this when i put csvResults into a csv file andi open this csv file in excel...everything is showing in columns..there is just one row. i am thinking this is because the LF character has been taken out. But now when i open it in notepad the 'Square' is not there.
Does anyone have any better solutions to get rid of this 'square' (LF) from notepad and make excel still work.
can i replace the bit or character in byte array so that notepad would know that it is a LF and would interpret that rather than showing a 'square'
something like this maybe?
for (int j1 = 0; j1 < csvResults.length; j1++)
{
if ((char)csvResults[j1]!='\n')
csvResults1[j1] = csvResults[j1];
else //put a character here that notepad would understand as LF
{
System.out.println("Value: " + csvResults1[j]);
csvResults1[j]=10;
}
}
no, you can not replace the character, because you need an aditional character.
If I'd be you, I'd rather substitute that in a String with replaceAll, or add the missing \r when I'm writing the bytes to disk.
btw, in case that's sufficient: a more sophisticated edior than Windows Notepad will do the trick and accept \n as linebreak.
moving to a more sophisticated editor than notepad is the last option.
yes thanks yawmark.
if i do this i get an 'invalid character constant' compiling error ...
String toWriteA = new String(csvBytes);
toWriteA.replace('/n','/r/n');
> looks like wordpad adds /r/n by itselfNot quite. WordPad doesn't add any characters; it interprets '\n' as a proper new line, like most text editors do. Notepad doesn't, which is why it prints the "square"; it does so for every character it doesn't