Results 1 to 4 of 4
Thread: Get the data from arraylist
- 01-11-2012, 11:12 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
Get the data from arraylist
Iam trieing to save the data from my arraylist to a file.
When the file is saved this is in it:
naam1
naam2
model.Turn@6cd5cc1f
model.Turn@484c3f0b
model.Turn@5bf1042
model.Turn@42c46000
model.Turn@6a7ac23e
So it doesn't work proper.
this is my save code:
Java Code:private void saveLeg(File file) { FileIO legFile = new FileIO(file); Leg legread = returnLeg(); String player1 = legread.getNameP1(); String player2 = legread.getNameP2(); ArrayList turn1 = legread.getTurns(1); ArrayList turn2 = legread.getTurns(2); legFile.save(player1, player2, turn1, turn2, file); }Java Code:public void save(String player1, String player2, ArrayList<Turn> turnsPlayer1, ArrayList<Turn> turnsPlayer2, File f) { /* */ try /* */ { /* 128 */ if (!f.getName().endsWith(".leg")) /* */ { /* 130 */ f = new File(f.getAbsolutePath() + ".leg"); /* */ } /* */ /* 135 */ FileWriter fw = new FileWriter(f, false); /* 136 */ BufferedWriter bw = new BufferedWriter(fw); /* 137 */ String s = ""; /* 138 */ int Size = turnsPlayer1.size() + turnsPlayer2.size(); /* 139 */ int p = 0; /* 140 */ for(int i = 0; i < Size;) /* */ { /* 143 */ s = s + "\r\n" + ((Turn)turnsPlayer1.get(p)).toString(); System.out.println(s); /* 144 */ i++; /* */ /* 146 */ if (i < Size) { /* 147 */ s = s + "\r\n" + ((Turn)turnsPlayer2.get(p)).toString(); /* 148 */ System.out.println(s); i++; /* */ } /* */ /* 152 */ p++; /* */ } /* 154 */ bw.write(player1 + "\r\n" + player2 + s); /* 155 */ bw.close(); /* */ } /* */ catch (IOException ex) { /* 158 */ Message.error("Fout! " + ex); /* */ } /* */ } /* */ }
-
Re: Get the data from arraylist
Looks like you need to give one more more classes (I think in particular your Turn class) a decent toString() representation since what y9ou're seeing is a default toString() result, one obtained when you don't properly override this method.
- 01-11-2012, 11:35 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
Re: Get the data from arraylist
Thanks for your reply! Got it working indeed. forgto to create a toString().
You are the man! =D
-
Similar Threads
-
Finding the data in Arraylist
By nickliutw in forum New To JavaReplies: 29Last Post: 09-08-2011, 04:05 PM -
Multiplying specific data within a arraylist
By fiefa in forum New To JavaReplies: 6Last Post: 02-01-2011, 08:54 AM -
Load data from file to ArrayList
By humbug in forum New To JavaReplies: 3Last Post: 01-05-2011, 11:53 AM -
Using arrayList to store data from one class to another.
By nickc88 in forum New To JavaReplies: 3Last Post: 03-28-2009, 05:02 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks