You Are Here:

Community: Developer Discussion Boards

#1 Old FileConnection/InputStream reading problem - 2006-06-28, 11:18

Join Date: Jun 2006
Posts: 8
badquek
Offline
Registered User
Hi,

I am facing a problem with reading in data from a file using FileConnection.

Cannot seem to read in any data from a file exceeding a certain file size.

Below is a sample extract from my code which gives the problem:

InputStream in=null;
ByteArrayOutputStream bStrm=null;
FileConnection fc = null;

byte[] byteArray=null;
byte[] raw = null;

try{
fc = (FileConnection) Connector.open("file://"+sfile.getPath()+
sfile.getFilename());

in = fc.openInputStream();
int noOfBytesRead=1;

for(int i=1; i<=numChunks; i++){

bStrm = new ByteArrayOutputStream();
noOfBytesRead = 1;

while(noOfBytesRead != -1) {
byteArray = new byte[1];
//if(in==null)
// System.out.println("in is null");
//if(byteArray==null)
// System.out.println("byteArray is null");
noOfBytesRead = in.read(byteArray);

if (noOfBytesRead != -1) {
bStrm.write(byteArray,0,noOfBytesRead);
//System.out.println("byte stream write");
}
}

raw = bStrm.toByteArray();

}
return;
}
catch(Exception e){
System.out.println(e);
}
finally{
if(in!=null)in.close();
if(fc!=null)fc.close();
if(bStrm!=null)bStrm.close();
}


The code above gives a NullPointerException at the line: in.read(byteArray) when I open the InputStream of a file of size 16MB. But for a file that is 14MB in size below, there is no problem. Uncommenting the println statements reveal that InputStream in is not null.

I have varied the size of byteArray from 1 to 512 to 32K but it still fails.

Can anyone help? Thanks a lot.
Reply With Quote

#2 Old Re: FileConnection/InputStream reading problem - 2006-06-28, 18:51

Join Date: Jun 2006
Posts: 8
badquek
Offline
Registered User
oops... sorry forgot to mention that i have been testing on an S60 Nokia emulator. Hope this additional detail helps.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
CMsvSession Problem, Cannot access Inbox for reading SMS peter0815neu General Messaging 0 2006-04-24 16:00
Problem while reading file on c: on 6630. pankaj_hotwani Mobile Java General 1 2005-09-30 14:09
Problem with reading phone book details in noka 6210 master131181 PC Suite API and PC Connectivity SDK 0 2004-05-02 15:54
Problem reading txt-files from the net Elwoodini Mobile Java General 2 2003-04-07 04:04
Problem about Reading Chinese Text file? goeast Mobile Java General 0 2002-09-18 04:25

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia