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
New Developer
naitniq
Posts: 5
Registered: ‎09-16-2008

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
Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008

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.

 

Please use plain text.
New Developer
naitniq
Posts: 5
Registered: ‎09-16-2008

Re: A problem of read file

oh,file size cannot be lager than 256kb
Please use plain text.