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: search for specific line in the file

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    4
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default search for specific line in the file

    Hello Friends
    While am reading a file in java i would like to print some specific lines like which shows the path and file name(eg :/ posaa/ file / hii.txt).
    it has to print the as many lines as it contains in the file.
    i think i have to search for the (//) slach charater and print the whole line.
    But am not sure donot know how to start .
    Please help on this.
    Thank you in advance


  2. #2
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: search for specific line in the file

    Quote Originally Posted by Rajitha View Post
    ...how to start
    Well, if all you have to do is print all lines in the file that have a '/' character, then here is a way:

    1. Create a File object for the file name

    2. Create a Scanner object for the File object

    3. Make a loop that uses the Scanner nextLine() method to read
      each line of the file into a string.

    4. Use the String indexOf() method to determine whether that
      line contains the character '/' and print the line if it does.



    References:


    In addition to the Java API description in the above links, there are many on-line tutorials that demonstrate using these methods.

    What reference material are you using to learn Java from? Class notes? Textbook? What?

    Here's the reason I asked:

    Bottom line:
    If there were only one way to do things in Java (or anything else), it would be easy: Just discover the way or invent the way or get someone to show you the way and then get on with the rest of your life.

    The fact that there are many ways to do this specific task in Java means that meaningful help might depend on context: What have you learned (or are supposed to have learned) so far? What kind of programs have you written? Do you already know how to read lines of text from a file into a String? Stuff like that.


    Cheers!


    Z
    Last edited by Zaphod_b; July 16th, 2012 at 11:04 AM.

Similar Threads

  1. 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
  2. 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
  3. Reading a file line by line using the Scanner class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 17th, 2009, 07:34 AM
  4. How to Read a file line by line using BufferedReader?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM
  5. How to Read a file line by line using BufferedReader?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: May 19th, 2008, 06:32 AM