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(); } }