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 4 of 4

Thread: File reading from a specific point on a line

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default File reading from a specific point on a line

    Hi, I am having some trouble with reading a line at a specific point. For example I have several lines of data similar to this:

    Talsma,Tegan,743448,F,4F1,4K2,S4,950805,9051726485

    I want the buffer reader to read the numbers after the last comma. How could I do this? At first I considered using a for loop to count up to 8 commas. Is there an easier way?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: File reading from a specific point on a line

    You could tokenize the String manually by looping over each character to count the comma's, study the String API to see if there are methods that will allow you to split the string on the comma (hint), or use a regular expression to capture the group (advance and most likely overkill)

  3. The Following User Says Thank You to copeg For This Useful Post:

    lordofrandom (May 13th, 2013)

  4. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: File reading from a specific point on a line

    Oh...yeah I completely forgot about String.split. Thanks a lot!

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

    Default Re: File reading from a specific point on a line

    You could even use lastIndexOf and substring.
    Improving the world one idiot at a time!

Similar Threads

  1. Re: Reading a file line by line using the Scanner class
    By rajaveluswamy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 8th, 2013, 03:38 AM
  2. [SOLVED] reading a file line by line
    By shenaz in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 20th, 2013, 11:10 AM
  3. search for specific line in the file
    By Rajitha in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 16th, 2012, 09:18 AM
  4. Writing to a specific line in a text file
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 7th, 2011, 09:11 PM
  5. Reading a file line by line using the Scanner class
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM