Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Writing data to binary file.

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Writing data to binary file.

    Hello.
    I am a begginer in programming with Java. I have to write a simple program which can compress a .txt file (for example dictionary).
    Steps:
    - loading dictionary to memory (done)
    - building Huffman's tree (done)
    - writing it to .bin file (here is a problem)

    When I try to write my String (for example "011011") to .bin I have much bigger file than .txt, I have to convert it to binary type and save bit after bit but I have no idea how to do that. What should I do first? I have string and I have to save it to a .bin file. Maybe could anyone write a function which may do that?

    prototype of function:
    public void saveToBin(String txt)
    {
     
    }


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,548
    Thanks
    24
    Thanked 298 Times in 281 Posts

    Default Re: Writing data to binary file.

    No one will write the method for you, but we can direct you to the correct place.
    I'm not 100% sure, but I would say that you need to use a Byte Stream. Here is a brief tutorial that you should find helpful: Byte Streams (The Java™ Tutorials > Essential Classes > Basic I/O)
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

Similar Threads

  1. Binary File. Extract float data from binary file and put into array
    By cardinal152 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: June 13th, 2012, 07:31 PM
  2. Replies: 1
    Last Post: February 27th, 2012, 08:16 AM
  3. Writing formatted data to file
    By kafka82 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: June 20th, 2011, 03:07 PM
  4. displaying dyanamic data on jsp while core engine is writing it on text file
    By abhyudayaupadhyay in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: May 24th, 2011, 10:03 AM
  5. Reading a writing binary file
    By stu1811 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: July 30th, 2010, 12:58 PM