获取Java代码执行位置的位置 [英] Get location from where the Java code is executed

查看:309
本文介绍了获取Java代码执行位置的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以保存大量数据的swing Java应用程序(例如,您可以考虑游戏及其保存)。这些数据存储在文件而不是数据库中。

I have a swing Java application that preserves a lot of data (you can think of a game and its saves for example). Those data are stored in files rather than in database.

我想将这些文件保存在我的应用程序的安装文件(.jar文件)附近。有些用户(比如我) )用于删除操作系统的默认应用程序文件夹,当它变大时我不希望它们以这种方式丢失它们的数据。

I would like to keep this files near installation files(.jar file) of my application.Some users(like me) are used to delete default application folder of OS when it gets large and I don't want them to loose their data this way.

任何想法如何轻松地做到这一点?如何从正在执行.jar文件的程序中获取.jar文件的文件夹?或者如何将文件直接输出到某个包中?如何动态创建包(jar中的文件夹)?或者有一种简单的方法以其他格式分发Java应用程序然后.jar然后将生成的数据存储在安装(子)文件夹中?

Any ideas how to do this easily ? How do I get the folder of the .jar file from program that is executing form that .jar file? Or how do I output files directly into some package? How do I create packages(folders inside jar) dynamically ? Or is there a simple way to distribute Java application in other formats then .jar and then store generated data in installation (sub)folder ?

感谢阅读

推荐答案


我想将这些文件保存在我的$
安装文件(.jar文件)附近b $ b应用程序。有些用户(比如我)是
用于删除操作系统的默认应用程序
文件夹,当涉及到大
而且我不希望他们放弃他们的
这样的数据。

I would like to keep this files near installation files(.jar file) of my application.Some users(like me) are used to delete default application folder of OS when it comes to large and I don't want them to loose their data this way.

这(以及对普通用户帐户没有对应用程序目录的写访问权限的多用户系统的概念)是用户数据应保存在用户主目录中的原因,而不是应用程序安装文件夹附近的任何位置。

This (and the concept of multi-user systems with no write access to application directories for regular user accounts) is the reason why user data should be kept in the user's home directory, and not anywhere near the app installation folder.

这篇关于获取Java代码执行位置的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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