• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

ascii file to binary format

What is the most elegant way to copy an existing ascii file to a binary format?
0
happyloman
Asked:
happyloman
1 Solution
 
objectsCommented:
What do you mean by binary format?
Theoreticly all files are in a binary format.
0
 
yasser_helmyCommented:
The question is not clear. What do you mean by binary??
0
 
happylomanAuthor Commented:
OK, sorry my fault.

I was assuming that there was some kind of file format that I can write a string to a file (e.g. "i pledge allegiance to the flag") whereby the file contains the information but is not human readable, and yet I can programatically open the file and read the string back out.

Is this possible? (without doing some complicated encryptioning)
0
 
Venci75Commented:
you can save it in gzip format if you want:

FileOutputStream fos = new FileOutputStream("file");
java.util.zip.GZIPOutputStream zos = new java.util.zip.GZIPOutputStream(fos);

zos.write("some string".getBytes());
zos.flush();
zos.close();

to read it use:
FileInputStream fis = new FileInputStream("file");
java.util.zip.GZIPInputStream zis = new java.util.zip.GZIPInputStream(fis);

BufferedReader reader = new BufferedReader(new InputStreamReader(zis));

String str = reader.readLine();


Also - you ca archive this by wrapping the file stream by ObjectInputStream and ObjectOutputStream

use ObjectOutputStream.writeObject(); for example
0
 
objectsCommented:
There are infinite possibilities.
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Tackle projects and never again get stuck behind a technical roadblock.
Join Now