This is how I did it. It's not as straightforward as ObjectInput(Output)Stream.
I output first the number of links I have parsed into the file, then I output the URLs and the indegrees line by line. After that, I output each keyword in a separate line (there are quoted strings that can also be a single keyword), and output the links for this keyword on the next line.
When I read, I use a BufferedReader to read in the file line by line. The first line tells me how many links there are so that I can rebuild my Vector of links with their indegrees (I'm not using graph.) After I build up the Vector of the links, I read in a line of keyword, followed by another line of URLs, and at the same time add them to the Trie (I'm using a Trie.). So when the file is read, the Trie and the Vector are ready for searching. Also, I use a StringTokenizer to parse each line, since I use a space to separate all the strings in one line and add a "\n" at the end of the line when I write.
If you are implementing graph, or hashtable, you probably need to think about how to write them to a file in text format.
Good luck! |