I usually use Scanner for inputting from files, but now I'm trying to input a from a non-Java optimized file that contains both fixed-length strings (effectively char arrays, of varying lengths), and 32-bit integers. There is a specified format for this, but the integers and strings are interspersed. For example, this might be an input file:
Supposing that book, meow, and boom were four-letter char arrays and strawberry was a ten-letter char array. I know what the format is ahead of time, so I can program it so it anticipates when a 4-char array/10-char array/32-bit integer/etc. is coming. The problem I've run into is, I don't know of a
Java input method that will handle both fixed-length strings and integers. It seems like there ought to be one, but if there is, I haven't encountered it.
Scanner is my default, but I don't see any way to input fixed-length strings with it. As there's no Java-specific formatting in my input files, next() and nextLine() aren't adequate.
BufferedReader does what I need for the fixed-length strings, but I just get (squares) when I try to input integers with it. Adding a StreamTokenizer to it doesn't help at all with the integers, and tokenizes the fixed-length strings incorrectly.
FileInputStream didn't seem to be doing anything correctly, and didn't work well at all for the fixed-length strings, giving me such nonsense as [B@45a877.
So far the best I've got is:
It doesn't work if I try making thirtyTwoBitInt a Byte or an int, either - BufferedReader can only read in fixed-length char arrays, not fixed-length integers.
So what is the class that I'm looking for that will let me input both fixed-length strings and 32-bit Integers, as I specify? I figure there has to be some such class out there, but I'm not finding it.
edit: Tried DataInputStream, too, but its method to input characters is two bytes at a time, and the characters in my file are one byte each.