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
Jeff_Lu
Posts: 384
Registered: ‎08-12-2008

how to load text file from other module?

Hi All,

 

I have to Module A, and B,

 

I want to load some text file saved within B Module from A module,

 

I have tried followed by this URL,

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/How_To_...

 

how it does not work for me.

 

what I am doing within A module

 

 

if(CodeModuleManager("B")!=0){
   Class cl = Class.forName("com.B.BClass");
   inputstream = cl.getResourceAsStream("/file");
   .....
}

 

 

however, it returns

 

FRIDG: could not find /file,

 

when I load this file within B module, everything is fine.

 

Thanks

 

 

 

Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009

Re: how to load text file from other module?

As discussed in this thread, you probably cannot do that. It seems to be a limitation of the BB api.

 

As a variation of something that according to that thread didn't work, you might try put a class like this in module B:

public class ResourceAccessor {

    public InputStream getResourceAsStream(String name) {

        return this.class.getResourceAsStream(name);

    }

}

you could then get at the resources using

Class.forName("ResourceAccessor").newInstance().getResourceAsStream("/file");

But in view of what was tried in the other thread, I don't hold much hope for this, either. (What was tried in the other thread was without the ".newInstance()".)




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
Developer
Jeff_Lu
Posts: 384
Registered: ‎08-12-2008

Re: how to load text file from other module?

Thanks,

 

This is a great idea,

 

I have got it done by other way.

 

I will try on different OS. and

 

post my code here.

 

 

Please use plain text.
Developer
Jeff_Lu
Posts: 384
Registered: ‎08-12-2008

Re: how to load text file from other module?

ContentConnection cc = (ContentConnection)Connector.open("cod://module/path/file.txt");

Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009

Re: how to load text file from other module?

Very cool. Do you know the actual type of object returned by Connector.open()?




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
Developer
Jeff_Lu
Posts: 384
Registered: ‎08-12-2008

Re: how to load text file from other module?

Honestly,

 

I can not say everytype that return from Connector.

 

this is documented by RIM, However, I believe the object which is returned by Connector.open depends the protocol.

 

for example: Http,it is httpconnection....

 

Thanks.

 

Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009

Re: how to load text file from other module?

No, I meant specifically when the argument started with "cod://". I guess I can set up such an experiment myself; just curious if you knew.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.