I have a project that requires parsing a positional flat file and would appreciate some sample code if anybody has one. Basically, the app should read a file line by line and parses each line by position.
i.e.
Field1Field2Field3Field4Field5
Field1 starts at offset 0, length 6 Field2 starts at offset 7, length 6 etc.
Each field contains actual values. In addition to this, I will need to attach each value with a specified key, but I'm unsure what the best approach to do this is.
FileReader fr = new FileReader("file.text"); BufferedReader first = new BufferedReader(fr); String line= new String(); while ((line = first.readLine()) !=null) {
//now take the substring for this line.... from 0 to 6 //(counter) and add 6 to counter for next substring... }
I appreciate the feedback. That's exactly what I ended up doing. I was hoping for something more simplistic, like a union ... but, this will have to do for now! Thanks again!