简体   繁体   English

用户在应用程序安装过程中给出的应用程序路径

[英]Application path given by user during application installation

I am deploying a Java application. 我正在部署Java应用程序。 User chooses the installation directory of the app. 用户选择应用程序的安装目录。 I want to get that path so that i can pass the path for making a sqlite DB der. 我想获得该路径,以便我可以通过该路径来创建sqlite DB der。

Mostly it will be something like : 通常情况是:

C:\Program Files\My App Name

or 要么

C:\Program Files(x86)\My App Name

The problem is I cannot hardcode the DB location in my code, beacuse i want my application to have the flexibility to be installed on user's choice of path. 问题是我无法在代码中对数据库位置进行硬编码,因为我希望我的应用程序具有可根据用户选择的路径进行安装的灵活性。

You can pass path dynamically in the run configuration of the Eclipse/IDE 您可以在Eclipse / IDE的运行配置中动态传递路径

-Dfilepath="C:\Program Files\My App Name"

Right click on project in the Explorer window --> Run As --> Run Configuration. 右键单击资源管理器窗口中的项目->运行方式->运行配置。 Then go to Arguments tab. 然后转到“参数”选项卡。

Edit : Suppose you get the path of DB from user and then put it in the file C:\\Config\\config.txt . 编辑 :假设您从用户那里获取DB的路径,然后将其放在文件C:\\ Config \\ config.txt中 Now this txt file has your actual path where you want to create your db. 现在,此txt文件具有您要在其中创建数据库的实际路径。 So through your java program you can read this file and get the path. 因此,通过Java程序,您可以读取此文件并获取路径。

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

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