Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6532609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:01:33+00:00 2026-05-25T10:01:33+00:00

im trying to write image data to a text file as a base 64

  • 0

im trying to write image data to a text file as a base 64 string its working if it doesnt contain to much information but when it contains quite a bit of information it crashes the application saying that its out off memory below is my code:

package com.search.visual;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Environment;
import android.util.Base64;
import android.util.Log;
import android.widget.Toast;

public class SavePhotoTask extends AsyncTask<byte[], String, String>{
    String name;
    byte[] num;
    @Override
    protected String doInBackground(byte[]... params) {
        // TODO Auto-generated method stub
    File photo = new File(Environment.getExternalStorageDirectory(),".vis/image.xml");

    name = Base64.encodeToString(params[0], 0);



    //return base64String;
    if (photo.exists()){
        photo.delete();
    }
    try{



        FileWriter fi = new FileWriter(photo.getPath());
        fi.write("<Image>\n\t<Data>");
        fi.write(name);

        fi.write("</Data>\n</Image>");
        fi.close();


    }catch (IOException e) {
        // TODO: handle exception
        Log.e("pictureDemo","exception", e);
    }


    return (null);
}

    }

am i doing something wrong or is there a better way to do this?

thank you in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:01:34+00:00Added an answer on May 25, 2026 at 10:01 am

    Sounds like you’re simply running out of RAM. One reason this is happening is because you’re holding the entire original image and the entire base-64 encoded image in memory, all at once, even if only briefly. Try writing the data out a chunk at a time in a for loop, using the variation:

    encodeToString(byte[] input, int offset, int len, int flags)
    

    And encoding and writing a few thousand bytes at a time

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to place text view on image view of particular size, but
I've been trying to write a small file server. I got it to the
I'm trying to write a code, what would save the content of a picturebox
I have rich-text file with a few images and text. In my Cocoa app
I am trying to create a separate model class for image uploading, which was
I am trying to write a breadcrumb navigation by using XSL to transform XML.
I am trying to convert emoticon codes into emoticon images. I want to write
Possible Duplicate: Image Button in BlackBerry Is there a way to have a picture
So I got a problem with saving my pdf. I want to create an
sadly i am totally new to jquery-writing and after googling for 12 hours to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.