在Java中使用相对目录路径 [英] Using relative directory path in Java

查看:118
本文介绍了在Java中使用相对目录路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用相对路径来查找Java类中的可执行文件,而不是使用硬编码的行,但使用的方法如下:

I am trying to use a relative path to locate an executable file within a Java class instead of hard-coded lines which worked, but using something like:

final static String directory =../../../ ggla / samples / obj / linux_x86

失败...在Java中使用相对路径的正确方法是什么?

fails... what is the proper way of using a relative path in Java?

推荐答案

最可能的解释是你的当前目录不在你认为的地方。您可以检查user.dir的系统属性以查看应用程序的基本路径,或者您可以执行以下操作:

The most likely explanation is that your current directory is not where you think that it is. You can inspect the system property of user.dir to see what the base path of the application is, or you can do something like this:

 System.out.println(new File(".").getCanonicalPath());

就在您使用相对路径调试相对引用开始的地方之前。

right before you use that relative path to debug where your relative reference starts.

这篇关于在Java中使用相对目录路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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