• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I need to divide a text file into blocks of 128 bits, how do i do it?

 
sura watthana
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have to divide a text file into blocks of 128 bits.
I think i must use the ByteArrayInputStream and ByteArrayOutputStream classes. my question is how would i do that?

is there any website showing how to user these two ByteArrayInputStream and ByteArrayOutputStream classes in detail.

or it would be much better if you could show me a portion of the code. so i get to learn how to do it.

Thanks

Sura
 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ByteArrayInputStream and ByteArrayOutputStream are for reading and writing to byte arrays. Perhaps you should look at the various methods of InputStream. In particular, the one which takes an array as an argument.
Be aware that in some text encodings, a byte does not equal a character so breaking text up in 128 bit blocks may screw things up big time.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need to divide the file? What is your goal? Do you realize that in many character encodings, bytes and chars are not interchangeable? All that being said, the easiest way to read a fixed number of bytes is DataInputStream's readFully method:

http://java.sun.com/j2se/1.5.0/docs/api/java/io/DataInputStream.html

And it sounds like you could benefit from Sun's I/O tutorial: http://java.sun.com/docs/books/tutorial/essential/io/index.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic