Reputation: 57
hereis my code.... I am getting a NumberFormatException and idk whow to solve it.. newbie and totally stuck, really need the help
public class AcccountArray {
public static void main(String[] args)
{
//Scan the file and save account details to array
File file = new File ("customers.txt");
System.out.println("Path : " + file.getAbsolutePath());
try{
Scanner scanner = new Scanner("customers.txt");
String[][] Account = new String[Integer.valueOf(scanner.nextLine())][3];
for(int i=0;i<Account.length;i++)
{
Account[i][0]=scanner.nextLine();
//System.out.println(Account[i][0]);
Account[i][1]=scanner.nextLine();
//System.out.println(Account[i][1]);
Account[i][2]=scanner.nextLine();
//System.out.println(Account[i][2]);
}
scanner.close();
error:
java.lang.NumberFormatException: For input string: "customers.txt"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.valueOf(Unknown Source)
at AcccountArray.main(AcccountArray.java:15)
li. 15 is
String[][] Account = new String[Integer.valueOf(scanner.nextLine())][3];
Upvotes: 0
Views: 144
Reputation: 159874
Use the constructor for Scanner
that accepts a File
so that the scanner instance is not using a String
source:
Scanner scanner = new Scanner(new File("customers.txt"));
Since you already have this reference you can use
Scanner scanner = new Scanner(file);
Upvotes: 4