GeeCON Prague 2014*
The moose likes I/O and Streams and the fly likes I need to divide a text file into blocks of 128 bits, how do i do it? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "I need to divide a text file into blocks of 128 bits, how do i do it?" Watch "I need to divide a text file into blocks of 128 bits, how do i do it?" New topic
Author

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

sura watthana
Ranch Hand

Joined: Sep 13, 2004
Posts: 77
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

Joined: Oct 29, 2001
Posts: 8915
    
    8

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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


There is no emoticon for what I am feeling!
 
GeeCON Prague 2014
 
subject: I need to divide a text file into blocks of 128 bits, how do i do it?