Results 1 to 5 of 5

Thread: writing to binary files

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2001
    Posts
    37

    Unhappy 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.

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2001
    Posts
    37
    ok thanks for the advice

  4. #4
    New Member
    Join Date
    Jun 2002
    Posts
    8
    ya encryption would be the best idea because writing to binary from java would just be a pain

  5. #5
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    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();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width