序列化对象并从Web Java下载

发布于 2025-02-14 01:01:33 字数 1251 浏览 4 评论 0原文

我有一个项目(Spring Boot,MVC),其中:

1。单击按钮时,应打开窗口,用户选择路径,并应将新创建的文件导出到那里用户的计算机。该文件是使用对象序列化创建的。

2。和另一个按钮以相反的顺序:文件导入,避免,对象获取。

我知道这是通过此形式解决的,但是我无法确切地弄清楚如何解决。

<form id="singleUploadForm" name="singleUploadForm">
     <input id="singleFileUploadInput" type="file" name="file" class="file-input" required />
     <button type="submit" class="primary submit-btn">Submit</button>
</form>

用静态保存路径序列化对象的示例:

SavedGame savedGame = new SavedGame(info1, info2, info3);

FileOutputStream outputStream = new FileOutputStream("C:\\Users\\Username\\Desktop\\save.ser");
ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);

objectOutputStream.writeObject(savedGame);

objectOutputStream.close();

我在Internet上没有找到解决此特定问题的解决方案,我只找到了很多此类教程 https://www.callicoder.com/spring-boot-file-upload-download-download-rest-api-example/ ,这不能直接解决我的问题。具体来说,我不明白在哪里插入我的序列化文件。

问题:是否有有关灭菌的明确教程或视频,然后是从网络中保存的?

我会为任何帮助感到高兴!我已经解决问题了一个星期...

I have a project (Spring Boot, MVC) where:

1. When the button is clicked, a window should open in which the user selects a path, and a newly created file should be exported there to the user's computer. The file is created using object serialization.

2. And in reverse order by another button: file import, deserialization, object acquisition.

I know that this is solved by this form, but I can't figure out exactly how.

<form id="singleUploadForm" name="singleUploadForm">
     <input id="singleFileUploadInput" type="file" name="file" class="file-input" required />
     <button type="submit" class="primary submit-btn">Submit</button>
</form>

Example of serializing my object with a static save path:

SavedGame savedGame = new SavedGame(info1, info2, info3);

FileOutputStream outputStream = new FileOutputStream("C:\\Users\\Username\\Desktop\\save.ser");
ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);

objectOutputStream.writeObject(savedGame);

objectOutputStream.close();

I didn't find a solution to this particular problem on the Internet, I only found a lot of such tutorials https://www.callicoder.com/spring-boot-file-upload-download-rest-api-example/ which don't solve my problem directly. Specifically in this I do not understand where to insert my serialized file.

The question: is there any clear tutorial or video on sterilization followed by saving from the web?

I will be very glad of any help! I've been solving the problem for a week now...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无戏配角 2025-02-21 01:01:34

如果通过“从网络中保存”,您的意思是如何在春季应用程序中生成序列化文件并允许用户下载文件,则本教程可能是您想要的? https://www.baeldung.com/spring-controller-return-image-文件

If by 'saving from the web' you mean how can you generate your Serialized file within your Spring app and the allow the user to download the file, this tutorial might be what you're looking for? https://www.baeldung.com/spring-controller-return-image-file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文