文件路径获取

public class Path
{  
 
 
  public static void getPath()  
  {  
      //方式一  
      System.out.println(System.getProperty("user.dir"));  
      //方式二  
      File directory = new File("");//设定为当前文件夹  
      try{  
          System.out.println(directory.getCanonicalPath());//获取标准的路径  
          System.out.println(directory.getAbsolutePath());//获取绝对路径  
      }catch(Exception e)  
      {  
          e.printStackTrace();  
      }  
      //方式三  
      System.out.println(FlieUpAndDown.class.getResource("/"));  
      System.out.println(FlieUpAndDown.class.getResource(""));  
      //方式4  
      System.out.println(FlieUpAndDown.class.getClassLoader().getResource(""));  
      System.out.println(FlieUpAndDown.class.getClassLoader().getResource("source.xml"));  
  }  
  public static void main(String[] args) throws Exception  
  {          
    String ip = InetAddress.getLocalHost().getHostAddress();  
      
     System.out.println(ip);  
     FlieUpAndDown.getPath();
      
  } 
}  

 

posted on 2017-02-10 15:52  让代码飞  阅读(186)  评论(0编辑  收藏  举报

导航

一款免费在线思维导图工具推荐:https://www.processon.com/i/593e9a29e4b0898669edaf7f?full_name=python