Java代码如何获取当前工作目录呢?

java问题王 Java每日一问 发布时间:2021-09-24 09:05:27 阅读数:3306 1
下文笔者讲述Java代码获取当前工作目录的方法分享,如下所示:
实现思路:
    使用以下代码,即可返回当前工作目录
	 String current = new java.io.File( "." ).getCanonicalPath();
        System.out.println("Current dir:"+current);
      String currentDir = System.getProperty("user.dir");
        System.out.println("Current dir using System:" +currentDir);
例:
package com.java265.other;
import java.io.IOException;
public class test {
	/*
	 * java265.com 获取当前工作目录的示例分享
	 */
	public static void main(String[] args) throws IOException {
		String current = new java.io.File(".").getCanonicalPath();
		System.out.println("当前工作目录:" + current);
		String currentDir = System.getProperty("user.dir");
		System.out.println("当前工作目录:" + currentDir);
	}
}
Java获取当前工作目录的方法分享
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

本文链接: https://www.Java265.com/JavaProblem/202109/1215.html

最近发表

热门文章

好文推荐

Java265.com

https://www.java265.com

站长统计|粤ICP备14097017号-3

Powered By Java265.com信息维护小组

使用手机扫描二维码

关注我们看更多资讯

java爱好者