java 将数据写入文件,如何通过Java将数据写入文件?

I want to make a GUI application that contains three functions as follows:

Add a record

Edit a record

Delete a record

A record contains two fields - Name and Profession

There are two restrictions for the application

You can't use database to store info. You have to use a flat file.

Total file should not be re-written for every add/delete operation.

So, my questions are mentioned below:

Q1. Which file format would be better? (.xml or .csv or .txt or any other)

Q2. How can we perform the add/delete operation without the whole file being re-written?

解决方案

As for the format - I would go with something as simple as possible. You don't want to have to deal with a bunch of markup processing, as using RandomAccessFile, you will going directly to a byte position. A fixed width style format would be good, so that based on the record number, you can calculate the starting position of a record or field in the file, without having to read everything in the file. The fields would then be padded out to the fixed width with spaces or some other suitable character.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值