| Reply | « Previous Thread | Next Thread » |
|
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. |
|
oops... sorry forgot to mention that i have been testing on an S60 Nokia emulator. Hope this additional detail helps.
|
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| 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 |