Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Simple enough....???

jeffsujeffsu Posts: 1Member
[b][red]This message was edited by jeffsu at 2006-4-4 15:29:38[/red][/b][hr]
[b][red]This message was edited by jeffsu at 2006-4-4 15:29:31[/red][/b][hr]
Okay, working on this file. It needs to input information from a file (phonebook.dat) that has last name, first name, phone number. It needs to be stored in a 2d array so that each bit of info could be individually pulled out. Then it needs to print the whole thing.

This is what phonebook.dat looks like:

Lange Albin 444-2742
Richards Carole 243-5816
Powell Melanie 683-2309
Poshard John 353-2301
Schmidt David 674-7762
Wagoner Rodney 699-9820
Brown Roberta 444-2854
Barnette Amy 822-2273
Davis Darin 354-5611
Gasper Reginald 243-3158
Hohulin Matt 676-2911
Lampkin Kenneth 694-1626
Maxion Patsy 742-2151
Contrary Mary 677-2243
Jordan William 222-5361
Barnes Michael 861-3344
Burnett Julie 651-4442
Ramsey Richard 987-9876
Lead Brenda 443-7665

Here is what my code looks like. It always gets hung up on the catch statement... HELP!! It's driving me crazy. The output in the program should look pretty much exactly like the original phonebook.dat file. SHould be so simple, but it just doens't work.. grr!

package lab10;
import java.util.Scanner;

public class Main {

public Main() {

public static void main(String[] args) {


public static void populateArray() {

String firstName; // To temp store input First Name
String lastName; // To temp store input Last Name
String phoneNumber; // To temp store input phone number

int numRows = 18;
int numCols = 2;

String[] [] phone = new String [numRows] [numCols];

File tempFile = new File ( "phonebook.dat" );

try {
Scanner scan = new Scanner (tempFile);

int i = 0;
while ( scan.hasNext() ) {
lastName =;
firstName =;
phoneNumber =;

phone[i][0] = lastName;
phone[i][1] = firstName;
phone[i][2] = phoneNumber;


} // Ends WHILE loop

} // Ends TRY

catch ( Exception exception ) {
System.out.println("An Error Occurred: File Not Found.");
} // Ends CATCH

// Print
System.out.println("Phone Book: ");
for (int x = 0; x <= numRows; x++) {
for (int y = 0; y < numCols; y++) {
System.out.print( phone[x][y] );
} // Ends INNER 'for'
}// Ends OUTER 'for'


Sign In or Register to comment.