View Single Post
Join Date: Oct 2008
Posts: 37
Reputation: l_03 has a little shameless behaviour in the past 
Solved Threads: 0
l_03 l_03 is offline Offline
Light Poster

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

 
0
  #4
Nov 17th, 2008
Originally Posted by javaAddict View Post
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"));



oh,,thank you very much for the help guyzz,,,this will be a great help...

ah now i see,,,

so if i will use string.split...

how will i declare the variables?????will it be the same with what i did???...i am really confused anyway...
Reply With Quote