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: 174
Registered: ‎01-25-2011
My Device: Not Specified

Issue loading a html file from sdcard !!!

Hi frds,


I am trying to load a static html file frm the sdcard in my browser field. when i tried loading using "browser_field.requestContent("file:///SDCard/test.html")"  I am greeted with the message Error: unable to load a page..


Then i found out that we cannot load a file direclty , using the above synatx.. I followed the code below:


InputStream input = this.getClass().getResourceAsStream("/Article1.htm"); //file:///store
System.out.println("Input  "+input.toString());
DataBuffer buffer = new DataBuffer();
byte[] temp = new byte[ 1024 ];
// Read in the web page to the DataBuffer.
for( ;; ) {
int bytesRead = input.read( temp );
if( bytesRead == -1 ) {
buffer.write( temp, 0, bytesRead );

// Create an output stream that will be used by the Base64 code.
ByteArrayOutputStream output = new ByteArrayOutputStream();
Base64OutputStream boutput = new Base64OutputStream( output );
// Write out the special sequence which indicates to the browser
// that it should treat this as HTML data in base64 format.
output.write( "data:text/html;base64,".getBytes() );
boutput.write( buffer.getArray() );
output.close(); // Invoke the browser with the encoded HTML content.
System.out.println("Input  "+output.toString());
//r=new RichTextField(output.toString());



But now the issue with the above code is that getResourceStream tries to load a file that is existing in the resource folder... when i give the path of a sdcard i am  thrown a null pointer exception.. 


So, i want to know a way to loas a html file frm sdcard 


Thanx in advance!!!!!!!!!

Please use plain text.
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Issue loading a html file from sdcard !!!

I can't remember dong this, but it would seem from this other Thread:


I have tested what you are trying to do and it works.  This would suggest that the file is not where you say it is, i.e. is not in the base directory of your SD Card or is not called test.html.  Can you check this?

Please use plain text.
Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified

Re: Issue loading a html file from sdcard !!!

Thank you peter.. I am now able to display html file frm sdcard succesfully.... but now the issue is loading the external css related to that html file.... I tried making the css internal, which makes a succesfull attempt.. but i want to load the external css as a part of my project..
I have also tried to change the href path.. ot "file:///SDCard/test_123/test.css"... but no luck :smileysad:

Peter could you please through some light in that direction...
Please use plain text.