?
Solved

ascii file to binary format

Posted on 2002-06-27
5
Medium Priority
?
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

764 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