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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
New Developer
Posts: 5
Registered: ‎09-16-2008
My Device: Not Specified

A problem of read file

[ Edited ]

            i want read file to byte array,but I faile when file size more than 250K.

 

try{
FileConnection fconn = (FileConnection)Connector.open("file:///storage/home/user/myfolder/test.dat");
if (!fconn.exists())
{
System.out.println("The file do not exist!");
}
System.out.println(fconn.fileSize()); //works well

System.out.println( fconn.getName() );//works well
System.out.println( fconn.getPath() );//works well

InputStream input = fconn.openInputStream();
int length = (int)fconn.fileSize();//totalSize();

//allocating a temporary Buffer.
byte[] b = new byte[length];
//b is null
//reading data from a InputStream
input .read(b,0,length);

fconn.close();
}
catch (Exception ioe)
{
System.out.println(ioe.getMessage());
}

 

 

 

Message Edited by naitniq on 11-10-2008 10:13 AM
Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: A problem of read file

IO to limited resource devices over a mobile RF link is going to have problems and limitations.

Besides any device memory constraints that may impact array size limits, older network services

combined with the 2 minute timeout people have discussed could cause a connection loss before completion.

You really need to write IO code that can tolerate a variety of problems. Personally I haven't had a

problem so far with normal browsing code ( at least that a retry won't fix ) and if I'm talking to a server I control I'd design a transfer

mechanism that avoids the problem ( do you really need to download a whole file or does your server

support byte-range specifications etc?).

 

FWIW, you may want to print toString() on your error too as this tends to have more info sometimes.

 

Highlighted
New Developer
Posts: 5
Registered: ‎09-16-2008
My Device: Not Specified

Re: A problem of read file

oh,file size cannot be lager than 256kb