473,469 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Populating a three demensional array from a file

2 New Member
For a lengthy program which would be in no way helpful to discribe, I need to populate a three dementional array from a file and overwrite the file with the modefied arraylist later. The three dementional arraylist will always be in the form Integer[4][6][8] and the file should have one number on each line which corresponds to a place in the array. For some reason my code is not populating the array at all. Here is the portion of the code which populates the array:
Expand|Select|Wrap|Line Numbers
  1. public Integer[][][] populateLearning() throws FileNotFoundException 
  2.     {
  3.         Integer[][][] learning2= new Integer[3][5][7];
  4.         int pile=1;
  5.         int stoneNumber=0;
  6.         File f = new File("learningFile.txt");
  7.         FileReader fr = new FileReader(f);
  8.         BufferedReader br = new BufferedReader(fr);
  9.         String eachLine= "waiting to be filled";
  10.         int a;
  11.         int b; 
  12.         int c;
  13.         while (eachLine != null) 
  14.         {
  15.             for( a=0; a<3; a++)
  16.             {
  17.                 for(b=0; b<5; b++)
  18.                 {
  19.                     for(c=0; c<7; c++)
  20.                     {
  21.                         try {
  22.                             eachLine = br.readLine();
  23.                         } catch (IOException e) {
  24.                             // TODO Auto-generated catch block
  25.                             e.printStackTrace();
  26.                         }
  27.                         learning2[a][b][c]=Integer.parseInt(eachLine);
  28.  
  29.                     }
  30.                     c=0;
  31.                 }
  32.                 b=0;
  33.             }
  34.              //Prints out each line in file
  35.         }
  36.         return learning2;
  37.     }



Here is my code for refilling the array:


Expand|Select|Wrap|Line Numbers
  1. public void learn(Integer winner)
  2.     {
  3.         int adder=0;
  4.         if(winner==0)
  5.         {
  6.             adder=1;
  7.         }
  8.         if(winner==0)
  9.         {
  10.             adder=-1;
  11.         }
  12.         for(int i=1; i<stones.size(); i=i+2)
  13.         {
  14.             Integer[] compsMove= stones.get(i);
  15.             int a= compsMove[0];
  16.             int b= compsMove[1];
  17.             int c= compsMove[2];
  18.             learning[a][b][c]=learning[a][b][c]+adder;
  19.         }
  20.         for(int i=2; i<stones.size(); i=i+2)
  21.         {
  22.             Integer[] compsMove= stones.get(i);
  23.             int a= compsMove[0];
  24.             int b= compsMove[1];
  25.             int c= compsMove[2];
  26.             learning[a][b][c]=learning[a][b][c]-adder;
  27.         }
  28.         overWriteLearning();
  29.     }
  30.  
  31.     public void overWriteLearning()
  32.     {    
  33.         FileOutputStream fout;        
  34.         try
  35.         {
  36.             // Open an output stream
  37.             fout = new FileOutputStream ("learningFile");
  38.             // Print a line of text
  39.             int a;
  40.             int b; 
  41.             int c;
  42.  
  43.                 for( a=0; a<3; a++)
  44.                 {
  45.                     for(b=0; b<5; b++)
  46.                     {
  47.                         for(c=0; c<7; c++)
  48.                         {
  49.                             new PrintStream(fout).println (learning[a][b][c]);
  50.                         }
  51.                         c=0;
  52.                     }
  53.                     b=0;
  54.                 }
  55.                  //Prints out each line in file
  56.             // Close our output stream
  57.             fout.close();        
  58.         }
  59.         // Catches any error conditions
  60.         catch (IOException e)
  61.         {
  62.             System.err.println ("Unable to write to file");
  63.             System.exit(-1);
  64.         }
  65.     }
  66.  

Any suggestions on how I can get these to work?
May 19 '10 #1
0 1043

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Lamine Darbouche | last post by:
Can anybody help? I need to have three list boxes automatically populating each other, (ie when region is selected from the first listbox, it will populate automatically the second one which is...
1
by: Ward B | last post by:
Greetings. I'm somewhat new to this whole MySQL/PHP thing and need a little help. My web hosting service uses phpMyAdmin and at the bottom of the screen iis an area where I can upload a text...
6
by: Deano | last post by:
I needed to have a listbox populated by locations which are stored in tblLocations. However I wanted an "All locations" entry to be at the top of the listbox. This is not in the tblLocations. The...
4
by: Sangeetha | last post by:
I came across this array initialisation which I can't follow ---------------------------------------------- public static string AllOperators { get {
2
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
4
by: Robert P. | last post by:
I can easily store a one-dimensional array in viewstate ( see Test1 ) If I try storing a multi-dimensional array in the viewstate it's crapping out on me when it goes to serialize the array (not...
3
by: Nitin | last post by:
Hi all How to pass a 3-D array from the main program and access it in the subroutine. for example void main() { .....
1
by: Stephene | last post by:
New to the world of web design/php/mysql and need help please. What I'm trying to do: I would like a web page with three drop down menus each populated by a query The first represents...
1
by: spud379 | last post by:
i am doing an assignment in vb.net. i have to select at random from and array what i have is dim country(29) as string dim random as new random txtcountry.text = random.next(country) I...
1
by: elmbrook | last post by:
Hi I am trying to add an image to a listview box. I have the below code and according to me this should work. However, the image does not show at all. I can add an image when I manually add each...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.