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
Contributor
Posts: 48
Registered: ‎02-19-2011
My Device: Not Specified

How to use buffered IO with FileConnection?

Below is my code which reads some bytes in from a file and puts them in a buffer.  What I need to know is whether this code (which uses FileConnection and InputStream) uses buffered or unbuffered IO.  I can't find this information in the API docs.  If it is not buffered, how do I change it to buffered IO?  Better yet, where is this discussed in the documents so I can fix my output code also?  Thanks.

 

            FileConnection fc = (FileConnection)Connector.open(path);
            if(!fc.exists())
            {
                return;
            }
            // Read the file.   
            InputStream stream = fc.openInputStream();
            if(null == stream) return;    
            int size = (int) fc.fileSize();
            byte [] data = new byte[size];
            int count = 0;
            int bite = stream.read();
            while(-1 != bite){
                data[count] = (byte)bite;
                bite = stream.read();
                ++count;
            }
            stream.close();
            fc.close();