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

Java Development

Reply
Developer
Posts: 610
Registered: ‎10-17-2010
My Device: (BlackBerry Z10)-> Q10/Passport Dual Use

Loading .txt file into new screen

Does anyone know how to load the contents of a text file packaged locally with the app into a new screen?

 

My Flow:

 

1) List Items with titles

2) User clicks list item

3) Detect which item clicked

4) Based on click, load title, and content into a new screen

5) Go back to original screen (back key)

Also, is there sample code available for this? Seems simple enough. 

Highlighted
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Loading .txt file into new screen

You'll use Class.getResourceAsStream() to read the file from your jar.

 

See also Class.forName()

 

You get "Class" for your app name, then call getResourceAsStream().

 

Once you have the stream, you can read in the file contents as if it were a regular stream file.