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

Java Development

Posts: 445
Registered: ‎07-15-2008
My Device: Not Specified
Accepted Solution

Open txt file from mediacard


I was wondering how I can open a .txt file on a memory card so that I can read the content?

The file is at the path: file:///testfile.txt


Thank you for any help.


If your question was answered, please accept it as a sollution and / or give Kudos ;-)
Use the Search Field first! Maybe the question you want to ask already exists!
Posts: 120
Registered: ‎07-16-2008
My Device: 9000

Re: Open txt file from mediacard

You can open an input stream from the file using:

InputStream inputStream = null;
FileConnection fileConnection = (FileConnection) Connector.open( "file:///SDCard/testfile.txt");
if (fileConnection.exists()) {
inputStream = fconn.openInputStream();

 To get the input stream as text you can read it to a ByteArrayOutputStream and create a new String from the bytes.


ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[BUFFER_SIZE]; while (true) { int bytesRead = inputStream.read( buffer, 0, BUFFER_SIZE ); if (bytesRead == -1) break; byteArrayOutputStream.write( buffer, 0, bytesRead ); } byteArrayOutputStream.flush(); byte[] result = byteArrayOutputStream.toByteArray(); byteArrayOutputStream.close(); String resultString = new String(result);




Kurt Zettel | Chief Architect | Metova
Posts: 51
Registered: ‎04-16-2009
My Device: Not Specified

Re: Open txt file from mediacard



Is it necessary to sign code if you want to read and write content into a file.txt in the memory card?

Posts: 466
Registered: ‎03-04-2009
My Device: 8520
My Carrier: some

Re: Open txt file from mediacard

No. It does not require code signing.

But to be sure check http://www.blackberry.com/developers/docs/4.7.0api/index.html to see if there are any signed elements

Got resolved! Press kudo icon!