This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Reading multiple txt files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading multiple txt files " Watch "Reading multiple txt files " New topic

Reading multiple txt files

P Derlyuk
Ranch Hand

Joined: Feb 17, 2013
Posts: 33
I have a program where it is supposed to take a keyboard entry(userName) for a name. Then it searches for that name in two text files. One text file for the meaning(meaning.txt), and another for its popularity(names.txt). Then i have to print the line from each text file. When i type in a name (eg. Paul) that is in both text files, it says "Paul was not found." It should output its popularity and meaning. I attached what i did after main. Is there easier/simpler ways to read from multiple text files??

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 36563
Why have you got so much code in the main method? Why are all your methods static?
What order are the names in the two files? How do you know you will find the same name in the same location in both?
Why are you using nextLine and next together? Who told you nextLine returns the next line?
P Derlyuk
Ranch Hand

Joined: Feb 17, 2013
Posts: 33
O, sorry i forgot to remove this post. I figured it out already. I made a separate method that searches the text files i send it and returns the line i need. Thanks anyways!
I agree. Here's the link:
subject: Reading multiple txt files
Similar Threads
Linefeed problem while scanning a line
How to search a file???
Write a program that merges two files containing alphabetized lists of student records into a single
How to count and scan the number of characters in a line?
question about Scanner and Arraylist