简体   繁体   English

在何处以及如何存储文本文件以进行读/写

[英]Where and how to store text files for reading/writing

I have an app that accesses words from a csv text files. 我有一个可以从csv文本文件访问单词的应用程序。 Since they usually do not change I have them placed inside a .jar file and read them using .getResourceAsStream call. 由于它们通常不会更改,因此我将它们放置在.jar文件中,并使用.getResourceAsStream调用读取它们。 I really like this approach since I do not have to place a bunch of files onto a user's computer - I just have one .jar file. 我真的很喜欢这种方法,因为我不必将一堆文件放在用户的计算机上-我只有一个.jar文件。

The problem is that I wanted to allow "admin" to add or delete the words within the application and then send the new version of the app to other users. 问题是我想允许“管理员”在应用程序中添加或删除单词,然后将新版本的应用程序发送给其他用户。 This would happen very rarely (99.9% only read operations and 0.1% write). 这种情况很少发生(仅99.9%的读取操作和0.1%的写入操作)。 However, I found out that it is not possible to write to text files inside the .jar file. 但是,我发现无法写入.jar文件中的文本文件。 Is there any solution that would be appropriate for what I want and if so please explain it in detail as I'm still new to Java. 有没有适合我想要的解决方案,如果可以,请详细解释它,因为我还是Java的新手。

It is not possible because You can't change any content of a jar which is currently used by a JVM. 这是不可能的,因为您不能更改JVM当前使用的jar的任何内容。 Better Choose alternate solution like keeping your jar file and text file within the same folder 更好的选择替代解决方案,例如将jar文件和文本文件保留在同一文件夹中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM