I don't know how to write the elements of a TreeMap to a textfile, it needs to print each string key and its integer value on a separate line in the file.

The treemap I'm using is:

TreeMap<String, Integer> dictionary = new TreeMap<String, Integer>();

Java Code:
try{	
		File file = new File("temp");  
		FileOutputStream f = new FileOutputStream(file);  
		ObjectOutputStream s = new ObjectOutputStream(f);          
		s.writeObject(dictionary);
		s.flush(); 
		  
		  s.close();
	}
	catch (Exception e){//
		  System.err.println("Error: " + e.getMessage());
		  }
	}
The way I tried above does it partially right; you can see some of the strings written correctly but there is a bunch of corrupted characters and the integer values are completely corrupted.
I also tried using a Set iterator with a BufferedReader and that didn't work.