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: Reading a writing binary file

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Reading a writing binary file

    I have a binary file with a bit stream I need to modify. I need to change certain bits based on user input. An example in listed below. I can read the data into a byte array, but I'm not sure how to manipulate the data and then write it back out to a file. I need to preserve any leading zeros.

    Example File:
    00010010101101

    Desired File:
    10110010101101


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Reading a writing binary file

    Once in a byte array, you can use bitwise operators
    Bitwise and Bit Shift Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)

Similar Threads

  1. Help writing to a text file on a website!
    By straw in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: September 11th, 2011, 11:02 AM
  2. [SOLVED] Writing " to a File
    By Sai in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 29th, 2010, 05:21 AM
  3. [SOLVED] Writing integers to a file
    By dubois.ford in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 15th, 2010, 06:18 PM
  4. Reading and Writing Text Files
    By kappasig84 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 1st, 2010, 07:16 PM
  5. Writing Output To New File
    By Scottj996 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: January 6th, 2010, 07:25 PM