Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Parsing a Dat file !!!  RSS feed

 
Manoj Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys !
I am writing a servlet which parses a .dat file (which has records seperated by "~" as a delimiter) and then loads them into a database.I am using StringTokenizer class for parsing. Everything goes well if the Dat file has some value between two successive delimiters in each row and all the rows. But if there is an instance where to delimiters are together (eg. " ....~~...") then it throws NoSuchElementFoundException. I can't think of any other way of doing this. Please suggest.

ThanX
Manoj
 
Kenneth Reising
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume that having the delimiters together is intended to represent a 'Null' value?
In order to get around the parsing problem, one solution, albeit not really elegant, would be to run through and replace every instance of '~~' with '~ ~' (ie: put a space between them).
Depending on how you are reading the file in can alter how you would actually go about doing that.
HTH;
 
manoj bagul
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Manoj ,
Do something like this.
StringTokenizer temp = new StringTokenizer(data,"~");
while( temp.hasMoreElements() )
{
System.out.println(temp.nextToken()) ;
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!