search for specific line in the file
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
Re: search for specific line in the file
Well, if all you have to do is print all lines in the file that have a '/' character, then here is a way:
Originally Posted by Rajitha
- Create a File object for the file name
- Create a Scanner object for the File object
- Make a loop that uses the Scanner nextLine() method to read
each line of the file into a string.
- Use the String indexOf() method to determine whether that
line contains the character '/' and print the line if it does.
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:
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.