首页 > 后端开发 > 正文

如何查找java路径?

2024-04-08 11:00:50 | 我爱编程网

如何查找java路径?相关内容,小编在这里做了整理,希望能对大家有所帮助,关于如何查找java路径?信息,一起来了解一下吧!

本文目录一览:

如何查找java路径?

运行Java程序需要的工具软件所在的目录是(  )。

【答案】:A

运行Java的JDK-共包含五个目录,分别是:bin目录,该目录包含Java编译器、解释器和许多工具(如服务器工具、IDL、package工具等);lib目录,该目录包含Java库文件;jre目录,该目录是Java程序运行环境的根目录,它下面包含bin子目录,包括平台所用工具和库的可执行文件以及DLL文件;demo目录,该目录包含源代码的程序示例;include目录,该目录包含Win32子目录,都是本地方法的文件。

如何查找java路径?

Java获取程序运行的当前工作目录

使用下面这个PathUtil的getProgramPath()就可以获得当前程序运行的目录。

import java.net.URL;

import java.net.URLDecoder;

class PathUtil {

/**

* Get the env of windir, such as "C:\WINDOWS".

*

* @return the env of windir value.

*/

public static String getWindir() {

return System.getenv("windir");

}

/**

* Get file separator, such as "/" on unix.

*

* @return the separator of file.

*/

public static String getFileSeparator() {

return System.getProperty("file.separator");

}

/**

* Get line separator, such as "\n" on unix.

*

* @return the separator of line.

*/

public static String getLineSeparator() {

return System.getProperty("line.separator");

}

/**

* Get programPath

*

* @return programPath

*/

public static String getProgramPath() {

Class cls = PathUtil.class;

ClassLoader loader = cls.getClassLoader();

//

// Get the full name of the class.

//我爱编程网

String clsName = cls.getName() + ".class";

//

// Get the package that include the class.

//

Package pack = cls.getPackage();

String path = "";

//

// Transform package name to path.

//

if (pack != null) {

String packName = pack.getName();

//

// Get the class's file name.

//

clsName = clsName.substring(packName.length() + 1);

//

// If package is simple transform package name to path directly,

// else transform package name to path by package name's

// constituent.

//

path = packName;

if (path.indexOf(".") > 0) {

path = path.replace(".", "/");

}

path = path + "/";

}

URL url = loader.getResource(path + clsName);

//

// Get path information form the instance of URL.

//

String retPath = url.getPath();

//

// Delete protocol name "file:" form path information.

//

try {

int pos = retPath.indexOf("file:");

if (pos > -1) {

retPath = retPath.substring(pos + 5);

}

//

// Delete the information of class file from the information of

// path.

//

pos = retPath.indexOf(path + clsName);

retPath = retPath.substring(0, pos - 1);

//

// If the class file was packageed into JAR e.g. file, delete the

// file name of the corresponding JAR e.g..

//

if (retPath.endsWith("!")) {

retPath = retPath.substring(0, retPath.lastIndexOf("/"));

}

retPath = URLDecoder.decode(retPath, "utf-8");

} catch (Exception e) {

retPath = null;

e.printStackTrace();

}

return retPath;

}

}

测试类:

public class Test{

public static void main(String args[]){

String s = PathUtil.getProgramPath();

System.out.println(s);

}

}

如何查找java路径?

如何查找java路径?

1、要解决问题之前,我们需要下载java这个软件,在浏览器上搜索,记住下载的具体位置,方便下一步的操作。

2、接着我们需要安装Java在电脑上,我们可以看到它储存的

文件夹

,下载完毕后进行安装,这时候我们一定要注意,在安装时要勾选安装界面左下角更改目标文件夹,然后进行安装。

3、我们需要改换一下改文件存储的路径,点击打开目标文件选择界面,点击更改,创建一个名为Java名字的新文件夹,方便我们寻找,点击确定,进行下一步。

4、安装完毕后,我们就打开我的世界游戏软件,在游戏启动器界面,打开设置界面浏览。

5、打开之前创建的文件,找到自己刚才安装Java时的文件夹,选择Java文件夹和jre7文件夹,并且我们可以看到里面有个javaw.exe目标,确定之后保存,整个路径保存就算解决成功,打开游戏,就能快速的进入游戏。

Java是一种可以撰写跨平台应用程序的面向对象的

程序设计语言

。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学

超级计算机

、移动电话和互联网,同时拥有全球最大的开发者专业社群。

以上就是如何查找java路径?全部内容了,了解更多相关信息,关注我爱编程网。
与“如何查找java路径?”相关推荐