Thread: Array storage
View Single Post
  #5 (permalink)  
Old 04-14-2008, 11:18 AM
DonCash's Avatar
DonCash DonCash is offline
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 239
DonCash will become famous soon enoughDonCash will become famous soon enough
Hello bobleny,

To read in the contents of a text file and add each line to an array, use this code:

Code:
FileInputStream in = new FileInputStream("yourFile.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; String[] myarray; myarray = new String[4]; for (int i = 0; i < myarray.length; i++){ myarray[i] = br.readLine(); } in.close();
Then you can print out the array content to the console using:

Code:
System.out.println(myarray[0]); System.out.println(myarray[1]); System.out.println(myarray[2]); System.out.println(myarray[3]);
Hope this helps!
__________________
Did this post help you? Please
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
me!

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by DonCash : 04-14-2008 at 11:20 AM.
Reply With Quote