My task is to: Pick 10 of my favourite NBA or NHL players from 2 top teams and display the player name, team name, points, rebounds, and assists for each of them. I then have to store this information as a table in a .txt file (This part is completed).

The number of points, rebounds, and assists for each team should be read from a .txt file and loaded into appropriately named arrays. The name of the file should be entered by the user.

Ok, so I have done my research and made the .txt file but I'm unsure of how to read from a .txt file and load the stats into appropriately named arrays...Any help is kindly appreciated thanks!

Featured Replies in this Discussion

Hi there, well see if this helps the below piece of code will call getfilepath() method to ask the user to input the file path then it will parse the name to the readfile() method and the contents of the file will be displayed line by line. The only thing left for you to do is parse the contents of each line and get what you need and fill the specific array using an if…

... Do you mean as you execute it or when you type the path to your file? if its when you type the path to your file it might be due the fact that either you typed it incorrectly, it had white spaces or its just doesn't exist. put your file in 'c:\\' its easy and no mistakes

Probably there was something wrong with the file path/name that you typed in. You could print out the user's input so you have a record of what the path/file name were. Rather than using System.err.println("Error: " + e.getMessage()); in your catch block, use e.printStackTrace(); which will give you much more info on exactly what and where the problem was.

well see if this helps the below piece of code will call getfilepath() method to ask the user to input the file path then it will parse the name to the readfile() method and the contents of the file will be displayed line by line.

The only thing left for you to do is parse the contents of each line and get what you need and fill the specific array using an if else statement...

Hi David, welcome to DaniWeb.
I know your intentions were good, but we're here to help beginners build their own Java expertise. By posting complete pieces of code you run the risk that people will copy/paste without fully understanding, thus learning nothing (except maybe that it's easier to cheat than to work). It's much better to steer/prompt/guide them to write their own code.

well see if this helps the below piece of code will call getfilepath() method to ask the user to input the file path then it will parse the name to the readfile() method and the contents of the file will be displayed line by line.

The only thing left for you to do is parse the contents of each line and get what you need and fill the specific array using an if else statement...

Abruptly terminates the program, sending a return code of 0 to the operating system. Often used to end a program, but does have dangers in that it doesn't allow other parts of the program to close or free any resources they may have open.
In this particular case it's not needed, because the program will terminate normally at the end of the main method anyway.

Abruptly terminates the program, sending a return code of 0 to the operating system. Often used to end a program, but does have dangers in that it doesn't allow other parts of the program to close or free any resources they may have open.
In this particular case it's not needed, because the program will terminate normally at the end of the main method anyway.

Thanks! I had it removed and it was working properly. When I try running his code I get an error message saying (The system cannot find the path specified). Any clue why it says this?

Thanks! I had it removed and it was working properly. When I try running his code I get an error message saying (The system cannot find the path specified). Any clue why it says this?

Do you mean as you execute it or when you type the path to your file?

if its when you type the path to your file it might be due the fact that either you typed it incorrectly, it had white spaces or its just doesn't exist. put your file in 'c:\\' its easy and no mistakes

Probably there was something wrong with the file path/name that you typed in.
You could print out the user's input so you have a record of what the path/file name were.
Rather than using
System.err.println("Error: " + e.getMessage());
in your catch block, use
e.printStackTrace();
which will give you much more info on exactly what and where the problem was.

Abruptly terminates the program, sending a return code of 0 to the operating system. Often used to end a program, but does have dangers in that it doesn't allow other parts of the program to close or free any resources they may have open.
In this particular case it's not needed, because the program will terminate normally at the end of the main method anyway.

Sorry James, i just know how frustrating it is when code doesn't work, I did the complete program but after reading this wont post it thank you and hope to have a great time at www.daniweb.com :)

Probably there was something wrong with the file path/name that you typed in.
You could print out the user's input so you have a record of what the path/file name were.
Rather than using
System.err.println("Error: " + e.getMessage());
in your catch block, use
e.printStackTrace();
which will give you much more info on exactly what and where the problem was.