javase和javaee中获取文件路径的方法总结

1. javase中       

//获取src路径的一种方式

        String srcPath = this.getClass().getClassLoader().getResource("").getPath();
        
        //获取src路径的另一种方式
        String srcPath2 = InJavaSe.class.getClassLoader().getResource("").getPath();
        
        //获取路径的另一种方式
        String srcPath3 = this.getClass().getResource("/").getPath();
        
        //获取当前类路径<包含package路径>

        String classPath = this.getClass().getResource("").getPath();


2. javaee中

this.getServletContext().getRealPath("c.txt")

你可能感兴趣的:(java)