为什么我的JAR文件没有创建序列化? [英] Why does my JAR file not create a serialization?

查看:160
本文介绍了为什么我的JAR文件没有创建序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Java项目创建了一个jar文件。我现在甚至可以运行它,但是当我从JAR文件之外的普通二进制代码运行程序时,它不会保存正确存储的序列化文件。

I created a jar file from a Java project. I can even run it now, but it does not save the serialization file that is stored correctly when I run the program from normal binary code outside of the JAR file.

当你有一个jar文件时,你不能创建新文件吗?

Can’t you create new files when you have a jar file?

这就是我写这个文件的方式:

This is how I write the file:

FileOutputStream fileOut = new FileOutputStream("data/vocabulary.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(this);
out.close();
fileOut.close();

我的JAR文件如下所示:

My JAR file looks like this:

META-INF
    MANIFEST.MF
name
    stefankoch
        …

其中name / stefankoch / ...是我的项目命名空间。

where name/stefankoch/… is my project namespace.

我尝试创建一个数据 jar文件(root)中的目录,但它也不起作用。 jar文件所在的目录中还有一个 data 目录,但也没有这个目录。

I tried creating a data directory in the jar-file (root), but it did not work either. There also is a data directory within the directory the jar-file resides in, but that one is not taken either.

如何允许jar文件创建文件?

How can I allow jar files to create files?

推荐答案

基本上,你不应该将用户输入的信息添加到JAR文件,它们属于用户的主目录

basically, you should not add information entered by the user into a JAR file, they belong to the user’s home directory.

这可以通过

System.getProperty("user.home")

用户主目录中的文件也可以在JAR文件中使用。

And files within the user home directory can also be used from within a JAR file.

这篇关于为什么我的JAR文件没有创建序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆