简体   繁体   English

如何在Java中的脚本文件中添加相对路径?

[英]How to add relative path to my script file in java?

I have a directory structure as follows: 我的目录结构如下:

Service | 服务| src | src | com.abc.SaaSPlugin | com.abc.SaaSPlugin | myDb.sql myDb.sql

How can I get the relative path so that I can read the sql file and run the script. 如何获取相对路径,以便可以读取sql文件并运行脚本。

You could do something like 你可以做类似的事情

String absPath = new File("src/com/abc/SaaSPlugin/myDb.sql").getAbsolutePath();

You could also move the file to a different folder for ease of use ie 您也可以将文件移动到其他文件夹以方便使用,即

project
  -- Resources
  --src
    --abc ......

Put the myDb.sql in resources folder and then code will be.. 将myDb.sql放在resources文件夹中,然后将代码..

String absPath = new File("Resources/myDb.sql").getAbsolutePath();

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

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