Originally Posted by Rajitha
Well, if all you have to do is print all lines in the file that have a '/' character, then here is a way:
- 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.