Solved

ascii file to binary format

Posted on 2002-06-27
5
376 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
map related example 6 48
eclipse buid path vs tomcat lib path 10 23
String array comparison 4 34
Java: anonymous class 4 21
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

777 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