William Jefferson wrote:I've been steadily learning Java with the goal of replacing a legacy Visual Basic app with java. Now I'm to the good part - File I-O. But my historical VB files have integers stored as integer field. So far, everything I've read about file input in Java makes me think all data is stored as character strings, usually separated by a delimiter.
First, is that true? Care to elaborate for newbie?
No, that isn't true. Actually, all data is read in as a sequence of bytes. The most common tools take those bytes and order them as text because so many file-reads are for text. The tools which are designed around text / strings / character arrays are usually called 'Reader' like BufferedReader or FileReader. But if you use on of the base-input tools, they are called 'InputStreams' and get you bytes. One input stream implementation is the DataInputStream which has methods for reading ints, floats, chars, etc... from a Stream. Note, though, that what an Integer is in VB and what an Integer is in Java might be different - the byte order or
word order, as well as byte count could be different and give you unexpected results.
That is one of the reasons why using text to pass data between applications is so popular - text encoding has standard definitions, so if write and read with the same encoding the data you read will be the same.
Second, is there any way to read an old style interger field from a file in Java?
See above. Yes, either by:
1) Using the DataInputStream if your data is compatible
2) Using any type of 'InputStream' to read the bytes in and putting the bytes together in the correct order
I assume I can use VB to convert this old data into a java readable format. These are what I have always called "flat" files. I read the file once and build an array index based on customer name, display these names and allow the user to jump from customer to customer. There are multiple data records per customer, but only one customer name record per customer. In VB I had a fixed length record and could seek on record number. Am I still going to be able to do this in java? Again, care to elaborate for a newbie?
Sure, look at the different classes available in the
java.io package. There are tools that let you skip or seek about a Stream. Choose one that has the functionality you need.
You might also look into the java.nio package. It is a little more complicated, but there are some great tools and good tutorials out there as well.