+2  A: 

You might want to look at data-serialization methods such as JSON, Yaml, or a lightweight (file-based but not human-readable) database such as SQLite.

lfaraone
JSON/YAML are text based, so thats easy.Just make sure your reads/writes are serialized and you implement any locking needed and they should suit fine.
Matthew Watson
A: 

You can use JDBC-ODBC bridge driver and link to a TEXT-BASED ODBC connection.

After that, you can just use JDBC to select, insert, update or delete entries on the file.

But even though that will work, I would recommend you using HSQL, SQLite or any other lightweight database though. It will be faster and more reliable.

Good luck.

Pablo Santa Cruz
so there is no other way of accomplishing the requirement? coz my work is about network programming and i honestly dont believe i can learn about network programming by messing databases around.
lamsaitat
+1  A: 

I would go also with hsql which has a mode to store data in a text file

http://hsqldb.org/

still the db text file is not a simple txt file, it contains some sql statements with the data. http://hsqldb.org/web/hsqlDocsFrame.html

sample TEXT database file:

INSERT INTO YOUR_TABLE VALUES('CLIENT1','xyz', .....)
INSERT INTO YOUR_TABLE VALUES('CLIENT2','xyz', .....)
silmx
I forgot to say, the HSQL runs in embedded mode, you dont need to set up any database server! this is a big advantage for simplicity
silmx
As said above use HSQL its a good embedded DB. Its easier to do this than to use a on the fly reinvent the wheel mechanism.
Nuno Furtado
A: 

It's not Java, but MySQL supports a CSV table type. http://dev.mysql.com/doc/refman/5.1/en/csv-storage-engine.html

MySQL would handle all the hard stuff, like locking and multiple access, but leaving you with a file you could read directly without MySQL.

Brent Baisley
A: 

I suggest JavaDB. Many features such as embedded support and mobile support that is available.

rayyildiz
+1  A: 

I've used JAXB to serialize modest-sized data structures (e.g. lists) to XML file and back. Advantages:

  • JAXB is part of Java SE 6, no extra libraries needed.
  • (De)serialization takes about two lines of code.
  • XML is human readable.

Of course it's no replacement to any real database. For instance, any change in the data forces you to rewrite the whole file - but for small files it really doesn't matter. Sometimes it's simplicity that's needed.

Joonas Pulakka
+2  A: 

Installing a database as several other posters have suggested will buy you certain things such as transaction security and the possibility of expanding what you store (at the moment, you need just IP/port, but maybe later you'll store more things, and maybe more permanently?)

However, if your requirements are going to remain as simple as you state, then I'm going to controversially suggest that using a SQL database isn't the simplest solution (even though, as I say, for certain requirements, a database does buy you certain things).

A very simple solution would be simply to have some directory in which, every time a client logs in, you create a file whose name encodes the information you want (or a hash of identifying information, and store extra info in the file). Then, when the client logs off, you delete the file. Issues you'll need to be careful of include what happens when your app exits abnormally, splitting among several directories if you have more than, say, a couple of thousand clients (Windows in particular seems to go ape if you have too many files in a directory, even though principle you should be able to store as many as you like), and managing filing system "issues" (the virus checker is accessing a file just as you need to delete...).

This simple solution isn't actually as bad as it sounds: the filing system is actually designed to access and index things efficiently, just like a database.

Neil Coffey
+1  A: 

The easiest way is to maintain it in a database of some sort. You have not specified the requirements for the file format, but the obvious choice would be a CSV text format.

The H2 Database in particular has support for CSV tables.

jsight