简体   繁体   中英

How to get and write data in text file Like Database

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);
        }
    }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM