当前位置:   article > 正文

java 将数据写入文件,如何通过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.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/538341
推荐阅读
相关标签
  

闽ICP备14008679号