Solved

ascii file to binary format

Posted on 2002-06-27
5
374 Views
Last Modified: 2012-06-22
What is the most elegant way to copy an existing ascii file to a binary format?
0
Comment
Question by:happyloman
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 7115543
What do you mean by binary format?
Theoreticly all files are in a binary format.
0
 
LVL 3

Expert Comment

by:yasser_helmy
ID: 7124688
The question is not clear. What do you mean by binary??
0
 

Author Comment

by:happyloman
ID: 7126996
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
 
LVL 9

Accepted Solution

by:
Venci75 earned 100 total points
ID: 7127029
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
 
LVL 92

Expert Comment

by:objects
ID: 7128283
There are infinite possibilities.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now