This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
readLine()
Posted by Harald Ueland on March 10, 2001 at 11:35 AM
> Hi, > I really need help with this one. Im a beginner to Java and am trying to write a very simple program that reads input from .txt file ie.. John Smith 606984 > Bob Green 46528 > Steve White 12455 > and outputs them in alphabetical order...as in a phone book > ie... Green, Bob 46528 > Smith, John 606984 > White, Steve 12455 > Any help would be greatly appreciated. > Thanks again > Seamus You can use the readLine() method to do this. First you have to "connect" to the file with FileReader() and then use BufferedReader(): try { FileReader fr = new FileReader(String filename); BufferedReader br = new BufferedReader(fr); } catch (IOException e) {i.e write an Error message} line = br.readLine(); while (line != null) { line = br.readLine(); System.out.println(line); }
Before you can do this, you have to import java.io package. Now, you don't get them in alphabetical order...
Replies:
|