Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: If there are any field past what is expected in each record of the input file, how to ignore it.

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy If there are any field past what is expected in each record of the input file, how to ignore it.

    Hi,

    I have an delimited input file, which i read line by line to extract data.

    the Input file looks something like this:-
    Site Name,Room Number,Street Address,Town,City,State,,,,,,,,,,,,,,,,,,,,,,,
    CVS Pharmacy,,500 Troy,Latham,NY,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,
    ,,,,,,,,,,,,,
    ,,,,,,,,,,,,,,,


    The first line, is the header line.
    But there are some comma delimiters for no reason

    I need to process the data, ignoring any fields past what is expected.
    How can I do that.

    When i run the code, it gives me
    Exception: Cannot access the Drive where the Input Files existsjava.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1


    I know why it is coming, because of the extra delimiters after each line and a line with just delimiters.
    What java statement will help me skip lines where there is not data and also process lines only till the data present.

    Thank You.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: If there are any field past what is expected in each record of the input file, how to ignore it.

    You could split the String on a comma and then reverse loop over the array until you find a location that contains data. This would be the end of the record and you can ignore everything after this index.
    Improving the world one idiot at a time!

Similar Threads

  1. Replies: 19
    Last Post: March 15th, 2013, 03:11 PM
  2. setting a boolean in a field when being read from a file
    By ajw1993 in forum Java Theory & Questions
    Replies: 16
    Last Post: March 10th, 2013, 05:56 PM
  3. JSF - input field is not updated
    By rcbandit in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 19th, 2012, 04:10 PM
  4. Replies: 8
    Last Post: January 6th, 2010, 09:59 AM