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
ankityadav4u
Posts: 231
Registered: ‎03-16-2011
My Device: 9700, 9550, and JDE
My Carrier: AIRTEL, BSNL
Accepted Solution

how to get connection to local resource file

i have  a text file to read in resource bundle, but i am not able to getConnection to that file. i tried reading directly as "/demo/file1.txt" and using "cod:///demo/file1.txt" but no result

any suggestion???


available on: Monday to Friday, Indian standard (day) time : )
  • Give kudos by clicking on the star icon to say "Thanks!" if you feel this response is helpful.
  • Click "Accept as Solution" if this post was what you needed. so that people who are trying to help will not waste their time reading a thread where no help is needed.

Please use plain text.
Developer
paulhaenel
Posts: 220
Registered: ‎09-09-2008
My Device: Bold 9780
My Carrier: Telstra AU

Re: how to get connection to local resource file

I put my config files in teh same directory where a class need it (So I have only one class that consume the file, exposing its content as properties of the class). The code I use is this:

 

 

InputStream is = null;
try {
  is = this.getClass().getResourceAsStream("config.txt");
  LineReader lineReader = new LineReader(is);  
 _url = new String(lineReader.readLine());
} catch (IOException e) {
  e.printStackTrace();
} finally {
  if ( is != null) {
     is.close();
  }
}

 

 

-----------

Follow me on twitter: twitter.com/paul.haenel

If your issue is resolved, please mark this thread as solved.

Set the "Solution" mark on the post which contains the answer to your question.
Please use plain text.
Trusted Contributor
Albert_Anks
Posts: 151
Registered: ‎06-17-2010
My Device: Curve 8900
My Carrier: Vodafone

Re: how to get connection to local resource file

Hi ankityadav4u,

 

can you tel me what you actually want to do?

 

you want to use resource bundle for differrent language? or just want to read text file which you put in your res folder?

 

 


Feel free to press the kudos button  on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.

 

Please use plain text.
Developer
ankityadav4u
Posts: 231
Registered: ‎03-16-2011
My Device: 9700, 9550, and JDE
My Carrier: AIRTEL, BSNL

Re: how to get connection to local resource file

 hi Albert_Anks,

 

for now, m just want to read text.

 

 


above solution is i tried, but any other way in which we dont have to use streams???


available on: Monday to Friday, Indian standard (day) time : )
  • Give kudos by clicking on the star icon to say "Thanks!" if you feel this response is helpful.
  • Click "Accept as Solution" if this post was what you needed. so that people who are trying to help will not waste their time reading a thread where no help is needed.

Please use plain text.
Trusted Contributor
Albert_Anks
Posts: 151
Registered: ‎06-17-2010
My Device: Curve 8900
My Carrier: Vodafone

Re: how to get connection to local resource file

Sorry Dear,

 

But i dont know any other way in which you can skip to use Streams...

 

Regards,

Albert Anks

 


Feel free to press the kudos button  on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.

 

Please use plain text.
Developer
Eugen
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE
My Carrier: Vodafone NL

Re: how to get connection to local resource file

This code should work:

 

InputStream is = null;
try {
  is = this.getClass().getResourceAsStream("/config.txt");
} catch (IOException ignored) {
} finally {
  if (is != null) {
    try {
      is.close();
    } catch (IOException ignored) {
    }
  }
}

 

 

Please use plain text.