Results 1 to 1 of 1
- 10-03-2011, 03:05 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 25
- Rep Power
- 0
Writing the elements of a TreeMap to a text file
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>();
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.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()); } }
I also tried using a Set iterator with a BufferedReader and that didn't work.
Similar Threads
-
Reading from a text file, then writing back to Text Area in Reverse
By medic642 in forum New To JavaReplies: 8Last Post: 07-17-2011, 02:38 PM -
Writing into a text file
By africanhacker in forum New To JavaReplies: 3Last Post: 03-31-2011, 10:44 PM -
Im writing to a file and i want to skip lines while writing to a text file.
By Broden_McDonald in forum New To JavaReplies: 1Last Post: 02-27-2010, 01:29 AM -
writing text to file
By notwist in forum New To JavaReplies: 3Last Post: 04-25-2008, 04:20 AM -
Sorting Elements in a TreeMap
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks