0

I'm trying to develop a small program. I want to write and get data from a text file like if it were a database. I have some data ex:

User = abc,
Age = 12,
No = 154

I want to write that data in the text file and after I want so search data using User. I don't know how to that. Can anyone tell how to do this.

BufferedWriter writer = null;
try {
    writer = new BufferedWriter(new FileWriter("./output.txt"));
    writer.write("your data here");
} catch (IOException e) {
    System.err.println(e);
} finally {
    if (writer != null) {
        try {
            writer.close();
        } catch (IOException e) {
            System.err.println(e);
        }
    }
}
6
  • 1
    Why not just use a small footprint database for this task, such as SQLite? Commented Apr 23, 2013 at 5:19
  • object serialization maybe ? Commented Apr 23, 2013 at 5:20
  • no i want add it on txt file. Commented Apr 23, 2013 at 5:22
  • 1
    Why not use an XML file? It has the benefits of being a flat-file (which you want), and the ability to be queried like a database (which you want as well). Commented Apr 23, 2013 at 5:24
  • 1
    @Makoto You're preaching to the wrong choir, I've had firsthand experience with these situations where databases/modern data storage techniques are too complicated/unnecessary for people who are content with simply storing everything unencrypted on a file. Commented Apr 23, 2013 at 5:26

1 Answer 1

1

May I know why do you want this..?? Because as the request for read and write will Increase your code will reach the bottle neck. You want to perform heavy I/O operations for getting the lite data. Disk I/O is heaving is its own concurrent read restrictions. So I will not suggest you to use such approach for getting the lite data. You may put some heavy data like Images/ Videos/ Songs etc in files using some unique ID that will be a good approach but like this I will nor prefer you.. But at all you want to do this than go for property files which works on key and value. Put values token separated and split at the time of consumption.

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

1 Comment

thanks friend. i was used property file. that's good idea. thanks :D

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.