Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Mapping text file  RSS feed

 
biraji gafiff
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone, i have a text file that its data will be read and inserted into data base. Every field of the file has a specific position, for example name is from caracter 10 to 30 of the line with "name" identifier and so on.

I was doing this by reading the lines and call substring like substring(10,30) for name for example.
Is there a library or something that i can map these fields and use an abstration? I am worried because these positions could change and i would have to change everything.

Thanks in advance.
[ February 05, 2007: Message edited by: biraji gafiff ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A quick Google on "java fixed length fields" found XFlat and XML Convert. I have no idea if it's any good ... not updated since 1999 ... but there were a lot more hits to look through ... maybe one of them will help.

BTW: I share your concerns about putting field lengths and positions all over your code. Good points for being recognizing the risk. Even if you have to roll your own here, externalize the row structures to some kind of declarative description outside the code. I use a (proprietary) framework that generates code to parse COBOL records ... the input to the generator is fieldname, position, length, type and the output is Java code with the ugly substringing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!