• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting binary file to ACII file

 
sankar dunga
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
sankar dunga
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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: 42968
73
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic