gpt4 book ai didi

java - 是否可以将对象以人类可读的格式发送到文件?

转载 作者:行者123 更新时间:2023-12-01 07:37:32 26 4
gpt4 key购买 nike

我正在为我的高级 Java 类(class)开发一个项目,作业说他需要我们将对象发送到文件,这很容易,但他也希望该文件可供人类读取和编辑。我三天前给他发了邮件,他还没有回复,所以由于该项目还有 3 天就要到期,我陷入了进退两难的境地。

那么你们聪明的程序员是否能够告诉我这个显然我被遗漏的 secret 。

如何将对象发送到读起来像英语的文件?

I want to have the ability to both read and write a to-do item to a file. I see our application looking like:

  1. When it first starts, the program asks the user if there is a file containing to-do items. If so, the user will name the file, the program will read it in and continue.
  2. When the user decides to exit, the program will prompt the user - to ask if the to-do items should be saved to a file - if so, the user will name the file and the program will write them out in such a fashion that it can read them in again.

I want these file to be human readable (and editable). No binary data. No counting. My advice to you would be to have a method somewhere that looked like:

public ToDoItem getToDoItem(FileInputStream fis) {
// ...
}

and

public void writeToDoItem(FileOutputStream fos) {
// ...
}

最佳答案

考虑您的序列化模型。 ObjectOutputStream 可能会写入字节,但是是否有另一种方法可以表示对象并通过写入人类可读文本的其他输出流写入它?

关于java - 是否可以将对象以人类可读的格式发送到文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9866335/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com