View Single Post
Join Date: Dec 2007
Posts: 1,688
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 227
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: How to make an array in text file (help..)

 
0
  #3
Nov 17th, 2008
Look at your code:
  1. for (line = lnr.readLine(); line!=null; line = lnr.readLine()){
  2.  
  3. String account[] = new String[4];
  4. int count = 0;
  5.  
  6.  
  7. int accountNumber[] = Integer.parseInt(account[count][1]);
  8. int pinNumber[] = Integer.parseInt(account[count][2];
  9. int balance[] = Integer.parseInt(account[count][3];
  10. String name = account[count][4];
  11.  
  12.  
  13. System.out.println(accountNumber[0][1]);
  14. }

You read the line BUT inside the loop you don't do anything with it. Instead you call this:
Integer.parseInt(account[count][1]); .
The account array is not 2-D and the Integer.parseInt does not return an array.


Now inside the line you have something like this:
12345 1234 200000 Jerry Lopez

So If you use the split method:
  1. String [] array = line.split(" ");

The elements of the array would be:
0: 12345
1: 1234
2: 200000
3: Jerry
4: Lopez

Also for reading from a file try this shorter version:
  1. BufferedReader lnr = new BufferedReader (new FileReader("accountList.txt"));
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote