Forget what I said above the file had been overidden

.
Now when I do read from the file that does contain:
|
Code:
|
5
ahoy there
hello
me hearties
dear friends
well, shiver me timbers
gosh - how exciting
arrrrrrgh!
goodness!
you're a bilge rat
you are a horrid person |
The printout is instead:
|
Code:
|
Phrases@1672bbb
Phrases@6833f2
Phrases@12a73d9
Phrases@1bdb58
Phrases@dd75a4 |
From the format of the printout I can see that I am succesfully able to load from and save to the file but it is not in the english format I have expected it to be.
Is there anyway from both my dictionary code:
|
Code:
|
import java.util.*;
import java.io.*;
public class Dictionary
{
private ArrayList<Phrases> phrase;
public Dictionary() {
phrase=new ArrayList<Phrases>(30);
}
public void add(Phrases p){
phrase.add(p);
}
public void printout(){
System.out.println("The phrases in the dictionary are: ");
for (Phrases p:phrase) {
System.out.println(p.toString());
}
}
public void load(String pirateTxt) throws IOException{
Scanner infile=new Scanner(new InputStreamReader(
new FileInputStream("pirate.txt")));
int num=infile.nextInt();
infile.nextLine();
for(int i=0;i<num; i++){
String pi=infile.next();
String e=infile.next();
infile.nextLine();
Phrases p=new Phrases(pi,e);
phrase.add(p);
}
infile.close();
}
public void save(String pirateTxt) throws IOException{
PrintWriter outfile = new PrintWriter
(new OutputStreamWriter
(new FileOutputStream(pirateTxt)));
outfile.println(phrase.size());
for (Phrases p:phrase) {
outfile.println(p.toString());
}
outfile.close();
}
} |
And my Phrases code:
|
Code:
|
import java.util.*;
public class Phrases
{
private String pirate;
private String english;
public Phrases() {
pirate="unknown";
english="unknown";
}
public Phrases(String pi,String e) {
pirate=pi;
english=e;
}
public String getEnglish()
{
return english;
}
} |
Could someone take a quick look over this please and give me feedback about why it is reading the text file as shown?