0
我有一个创建2个txt文件的代码。它工作正常。但是当我将应用程序打包到.jar文件时,我无法找到我的txt文件,阅读他们的。我的文件不包含在jar文件中Java
try {
KeyGenerator kg = KeyGenerator.getInstance("DESede");
SecretKey key = kg.generateKey();
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(Cipher.ENCRYPT_MODE, key);
ObjectOutputStream oos = new ObjectOutputStream(new CipherOutputStream(new FileOutputStream("saves/data.ttg"), cipher));
oos.writeObject("" + CurrentMoney);
fos = new FileOutputStream("saves/key.ttg");
SecretKeyFactory skf = SecretKeyFactory.getInstance("DESede");
DESedeKeySpec keyspec = (DESedeKeySpec) skf.getKeySpec(key, DESedeKeySpec.class);
fos.write(keyspec.getKey());
fos.close();
oos.close();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
什么问题?
P.S我用的IntelliJ IDEA
P.P.S这是JavaFX项目(如果它可以有所作为)
文件将被添加到'.jar'只有当他们在您的应用程序的构建路径。您的应用程序是否应该只创建一次这些文件,然后再重复使用它们? – mumpitz
是的,它应该创建一次。 – GeniusPenius
请澄清:你是否试图在jar文件中打包文件并在运行时读取它们,或者你想在运行时(到文件系统)写文件,然后再读取这些文件? –