I am trying to read a 2mb file into a memory and then send that file to web server. But I am getting out of memory exception
500kb files are uploading. What could be the reason? Please shed a light on this.Code:FileConnection fileConn = (FileConnection)Connector.open("file:///" + pictureURI.getString(), Connector.READ); InputStream fis = fileConn.openInputStream(); long overallSize = fileConn.fileSize(); int chunkSize = 2048; int length = 0; while (length < overallSize) { byte[] data = new byte[chunkSize]; int readAmount = fis.read(data, 0, chunkSize); byte[] newImageData = new byte[rawImage.length + chunkSize]; System.arraycopy(rawImage, 0, newImageData, 0, length); System.arraycopy(data, 0, newImageData, length, readAmount); rawImage = newImageData; length += readAmount; } fis.close(); fileConn.close();
I tried this also in loop but no use, System.gc();
Thanks in advance.

Reply With Quote

