Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Contributor
flimsy
Posts: 13
Registered: ‎04-25-2011
My Device: BlackBerry PlayBook
Accepted Solution

FileStream.readMultiByte adds extra carriage return to every line

I have simple txt file called file1.txt which contains:

 

 

Line1
Line2

 

 

I have this code which reads the file and puts the contents into variable called str:

 

 

var file:File = File.applicationDirectory;
file = file.resolvePath("file1.txt");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.READ);
var str:String = fileStream.readMultiByte(file.size, File.systemCharset);
str = str.replace(/\n/g, File.lineEnding);
fileStream.close();
trace(str);

 

When I run this code I get this:

 

 

Line1

Line2

 

 

(there is an extra blank line at the end of each line!)

 

I searched all over and I understand text file created in Windows ads an extra line start after line end which Flash interprets as extra line hence I added recommended (below) to convert it to devices line end.... Any ideas how to overcome this?

 

str = str.replace(/\n/g, File.lineEnding);
Regular Contributor
Vemilyus
Posts: 54
Registered: ‎03-21-2011
My Device: 1st Gen BlackBerry PlayBook 16GB (Gift from RIM :D)

Re: FileStream.readMultiByte adds extra carriage return to every line

Maybe it works when you replace the regexp with a string that contains "\n".

This is a signature. Don't expect anything fancy, for I would use an image if I could. But I can't, so cope with it...
Contributor
flimsy
Posts: 13
Registered: ‎04-25-2011
My Device: BlackBerry PlayBook

Re: FileStream.readMultiByte adds extra carriage return to every line

 

str = str.replace(/\n/g, "");

 

This did the trick. Thanks