aspose file tools*
The moose likes Android and the fly likes problem in converting string to byte array. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "problem in converting string to byte array." Watch "problem in converting string to byte array." New topic
Author

problem in converting string to byte array.

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Hello everybody,

I am developing an application in that I want to upload image to the server. If image is less than 900 kb then application run fine. but when image is more than 900kb then it throws exception as java.lang.OutOfMemoryError.

my code is as follows



I have Base64 class which has method


What is wrong here?

Thanks in advance.

Life is easy because we write the source code.....
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

I would say your code is not properly created for mobile devices. You are reading the whole file into a byte array, then encoding it with Base64 to get a String and then again convert the whole String back to byte array. This will use a lot of memory for a mobile device to handle. Why don't you read the file in chunks like 100bytes at a time and send it to the output stream. That way you won't use that much memory...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in converting string to byte array.
 
Similar Threads
How can I recieve data from servlet on j2me application?
How to encode image in parts?
Reading image and convert it to Base64 format
read and write file in parts
java.net.ProtocolException: Does not support output