-
writing to binary files
I want to write data to a file but i want it to be written as
binary data so that no one could easily open the file and edit
it. The file will actually contain candidate names and ballot numbers so I prefer such data not to be in regular readable format.
Sample code anyone?
Any help will greatly be appreciated! Thanks.
-
Why don't you just encrypt it? You can get the JCE (Java Cryptography Extension) from sun's site which contains various cryptographic algorithms that you can use. I would just use DES (Data Encryption Standard) which is basicaly a symmetric (private key) 64 bit block cipher that uses a 56 bit key.
-
ok thanks for the advice :)
-
ya encryption would be the best idea because writing to binary from java would just be a pain
-
If thats too much hassle, then what you want is to write to an object ouput stream. ie
Code:
import java.io.*;
Candidate can = new Candidate();
ObjectOutputStream out = new ObjectOutputStream
(new FileOutputStream("candidates.dat"));
out.writeObject(candidate);
ObjectInputStream in = new ObjectInputStream (new
FileInputStream("candidates.dat"));
can = (Candidate)in.readObject();
in.close();