1

I am writing an application that stores references for books, journals, sites and so on. I mean I have already done most.

What I want is a suggestion regarding what is the best way to implement above specs?

What format text file should I use to store the library? Not file type but format. I am using simple text file at the moment. But planning to implement format as in below.

<book><Art of Human Hacking><New York><2011><1>
<journal><Achieving Maximum Speed In 802.11n><London><2009><260-265>

1st tag <book> and <journal> are type identifier. I have used ArrayList. Should I use multi dimensional ArrayList and store each item like below?

[[Art of Human Hacking,New York,2011,1][Achieving Maximum Speed In 802.11n,London,2009,260-265]]

I have used StringTokenizer and I cannot differentiate spaces. How do I fix this?

I have already implemented all features including listing all, listing unique, searching, editing, removing, adding. But everything is done to content without spaces.

1
  • I really like JSON. There are definitely going to be existing parsers for JSON in Java. It's shorter and parsed faster than xml. Commented Dec 20, 2011 at 18:59

1 Answer 1

1

You should use an existing serializer instead of writing your own, unless the project forbids it.

For compatability and human readability, CSV would be your best bet. Use an existing CSV parser to get your escaping correct (not that hard to write yourself, but difficult enough to warrant using an existing parser to avoid bugs). Google turned up: http://sourceforge.net/projects/javacsv/

If human editing is not a priority, then JSON is also a good format (it is human readable, but not quite as simple as CSV, and won't display in excel for instance).

Then you have binary protocols, such as native Java serialization, or even Google protocol buffers. These may be faster, but obviously lose the ability to view the data store and would probably complicate your debugging.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much but, will using serializer along with CSV make the text manipulation simple? Since I will need to do manipulation can you provide me link to any example where serializer is used along with array list in order to manipulate text file.
I was using serializer as a general term for converting objects to a writable format. If using the CSV library I linked to, then from what I can tell, for reading you would create a CSVReader object (passing in the file name as a parameter), and then call readRecord() to advance the row, and use the different get() methods to get the values of different columns (if you set the header names, then you can also get by header name). Eg: while(csv.readRecord()) { myArray.add(csv.get(0)); } to add every entry in the first column to an array (normally would create a sub object containing every col).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.