11-10-2008 07:39 AM - edited 11-10-2008 10:13 AM
i want read file to byte array,but I faile when file size more than 250K.
FileConnection fconn = (FileConnection)Connector.open("file:///storage/ho
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
catch (Exception ioe)
11-10-2008 07:57 AM
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.