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 6705311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:23:21+00:00 2026-05-26T07:23:21+00:00

I have following way of converting file to byte array and than to string

  • 0

I have following way of converting file to byte array and than to string and back.

        InputStream is = new FileInputStream(new File("c:/original.png"));
        String temp = Hex.encodeHexString(IOUtils.toByteArray(is));
        System.out.println(temp);
        byte[] b = Hex.decodeHex(temp .toCharArray());
        OutputStream out = new FileOutputStream(new File("c:/copy.png"));
        IOUtils.write(b, out);

It works OK. The problem is the size of temp string. If the c:/original.png file is 1523KB than the temp size is 3046KB. Is there more effective way of converting the file to the string that would not double the size of the file? (BTW I understand why it is about twice the size)

Alternatively, how would I go about compressing the temp string?

As far as the reason for the string. It is being stored in cache that will take only strings. The file is actually upload to the web server. Once the upload is about to be downloaded it will be pulled from cache rather than the database. And the cache is there to improve search performance via predictions that I don’t want calling the database each time someone searches.

  • 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-26T07:23:22+00:00Added an answer on May 26, 2026 at 7:23 am

    A more efficient encoding than Hex is Base64, the overhead tending toward a minimum of about 37% for large files. Unfortunately there’s no standard library for it, but Apache Commons contains a class to do this.

            String temp = Base64.encodeBase64String(IOUtils.toByteArray(is));            
            byte[] b = Base64.decodeBase64(s);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am converting images to byte array and storing in a text file using
I have the following line in my code which clearly returns a byte array:
I am converting some jpg images to png w/ imagemagick & have the following
i have following code for moving 4 picture around circular way,but it can rotate
I have two entity classes annotated in the following way @Entity class A {
I have written my code in following way in cocos2d. id actionTo = [CCFadeOut
I have defined a config section in my app.config in the following way: <?xml
I am using apache ant in the following way: I have projects P1, P2,
I have a Silverlight control derived from ContentControl. I use it in following way
What's the best way to have the following? Name: [Textbox] Inside a div? I

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.