• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in converting string to byte array.

 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic