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
Highlighted
Trusted Contributor
Posts: 109
Registered: ‎11-15-2011
My Device: blackberry 9800
My Carrier: beginner developer
Accepted Solution

read file from res folder blackberry

I want to read file from "res" folder on blackberry. The file that i used is a file javascript. I used this code

InputStream in = classs.getResourceAsStream("file.js");

 

 But i get "could not find this path" and I use also an other code

String srcFile = "/res/ressourcesWeb/file.js";
FileConnection srcConn = (FileConnection) Connector.open(srcFile, Connector.READ);
InputStream in = srcConn.openInputStream();

 

but i got an exception. Can any one help me to read the file and give me the right path that should I use?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: read file from res folder blackberry

Trusted Contributor
Posts: 109
Registered: ‎11-15-2011
My Device: blackberry 9800
My Carrier: beginner developer

Re: read file from res folder blackberry

i have the file in res folder. I didn't get what should I write in (*******) . If I should write the current class where I write this code. How it will find the file from res? the package is in folder "src" and my file in folder "res"???

  Class classs = Class.forName("************************");
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: read file from res folder blackberry

Actually the class you define is almost irrelevant.  You are just finding a class Object that belongs to the Application that has the res folder you are trying to read. 

 

So you can just do something like this:

Class classs = Application.getApplication().getClass();

is = classs.getResourceAsStream(.....);

Trusted Contributor
Posts: 109
Registered: ‎11-15-2011
My Device: blackberry 9800
My Carrier: beginner developer

Re: read file from res folder blackberry

I want to open Connector from file in filder res. I'm not able to get the right path

path="/res/web/name_file"

 

fconn_dir = (FileConnection) Connector.open(
path, Connector.READ_WRITE);

 

Thanks

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: read file from res folder blackberry

You can't use File Connection to read files that are assets of the Application.  You have to use the code supplied in the KB article I pointed you at.