Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Converting binary file to ACII file

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello sir,

I want convert the binary file into acii file by using java code.
I want to convert total binary file into another new ascii file.
Can anybody help me to do it, please[/b]


Regards
sankar
 
Rancher
Posts: 43028
76
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Binary data is not text data, much less necessarily ASCII data - so there is no conversion that will work in general. What may work is to base-64 encode the data; the Apache Commons Codec library can help with that.

Maybe you can tell us why you want to do this.
 
sankar dunga
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yah sure sir,

I want convert binary data from the source file to ascii file. Because i want to load data into database.
Ascii is the user friendly data type, so i want conver the data to ascii format before loading into the database.

Please give me the best suggestion to do this.
And what is the use of base64 encoding. Is it gives the result as ascii format.

Thank you.


Regards
sankar.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Base64 encoding will allow you to represent binary data in ASCII form and then load it into a database as character data.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
eg http://iharder.sourceforge.net/current/java/base64/
 
sankar dunga
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much.

Actually i tried with base64, The starting variable as follows

/*
private static final String base64code = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789" + /";
private static final int splitLinesAt = 76;

*/

But when i run this code it is giving different output than what i am expecting.

Any way i will try with your suggestion

Thank you

Regards
sankar
 
Ulf Dittmer
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sankar dunga wrote:But when i run this code it is giving different output than what i am expecting.


We might be able to help with this if a) we knew what output you got, and b) what output you were expecting. Seeing the actual code you used to base-64 encode the data -and to output it- would also help.
 
Sheriff
Posts: 22684
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd go for a BLOB database field and just store the data in binary form. PreparedStatement and ResultSet can handle binary values just fine.
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic