zoukankan      html  css  js  c++  java
  • Java中获得程序当前路径的4中方法

    Java中获得程序当前路径的4中方法:
    在Application中:

    import java.util.*;
    
    public class TestUserDir {
    
        public static void main(String[] args) {
            Properties property = System.getProperties();
            String str = property.getProperty("user.dir");
            System.out.println(str);
    
        }
    
    }

    或者:

    import java.util.*;
    
    public class getPath {
        public static void main(String[] args) {
            String s = System.getProperty("java.class.path");
            System.out.println(s);
        }
    }

    输出:F:/code/ec/JavaDBStudy

    在Servlet中:

    ServletContext servletContext = config.getServletContext();
    String rootPath = servletContext.getRealPath("/");
  • 相关阅读:
    1002 写出这个数
    1001 害死人不偿命的(3n+1)猜想
    Graph I
    Tree
    进程通信
    管道
    fork函数
    Priority Queue
    Search
    游戏 slider
  • 原文地址:https://www.cnblogs.com/cRaZy-TyKeIo/p/3447642.html
Copyright © 2011-2022 走看看