JAVA中获取路径】的更多相关文章

内容来自于snannan_268 关键字: java中获取路径 JAVA中获取路径: 1.jsp中取得路径:   以工程名为TEST为例: (1)得到包含工程名的当前页面全路径:request.getRequestURI() 结果:/TEST/test.jsp (2)得到工程名:request.getContextPath() 结果:/TEST (3)得到当前页面所在目录下全名称:request.getServletPath() 结果:如果页面在jsp目录下 /TEST/jsp/test.jsp…
在java中获取文件路径的时候,有时候会获取到空格,但是在中文编码环境下,空格会变成“%20”从而使得路径错误. 解决办法: String path = Parameter.class.getResource("").getPath();//得到路径 path = URLDecoder.decode(path,"utf-8");//关键啊 !…
package com.ygh.blog.realpath; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Properties; /** * 获取java下面的路径的演示 */ import org.junit.Test; public class RealPathTest { /** * 获取当前类所在的工程路…
1. java文件中获得路径 Thread.currentThread().getContextClassLoader().getResource("") //获得资源文件(.class文件)所在路径 ClassLoader.getSystemResource("") Class_Name.class.getClassLoader().getResource("") Class_Name.class .getResource("/&qu…
就目前的我来说最常用的两种获取路径的方法是  class.getRecource(filename) 和 class.getclassloader.getRecource(filename) 这两者的区别其实很简单就是路径的时候有点不同,这里主要讲两个参数,其他的路径获取,其他的话在根据相对路径逐一查找就行了 class.getRecource(filename): 参数"/" 表示获取根目录; (即我们常用到的bin目录[字节码文件存放的目录] " "  表示获取…
在class获取路径的方法,getResource有没有“\”的区别 System.out.println("" + this.getClass().getResource("").getPath()); video/software/JavaWorkspace/java_web_test/out/artifacts/java_web_test_war_exploded/WEB-INF/classes/cn/xx/dao/ System.out.println(&q…
总是忘记, 备份一下,方便下次用. 第一种: File directory = new File("");//参数为空 String courseFile = directory.getCanonicalPath() ;System.out.println(courseFile); 结果:C:\Documents and Settings\Administrator\workspace\projectName获取当前类的所在工程路径; 第二种: File f = new File(th…
转自:http://blog.csdn.net/appleprince88/article/details/11599805# 谢谢! 由于经常需要获取文件的路径,但是比较容易忘记,每次需要总需要查询,现在把这些方式写下来,方便自己的时候也方便大家了,如果大家在下面的方法遇到什么问题,可以留言. 各种获取方式如示例代码所示: package first.second; import java.io.File; public class GetPath { public static void g…
JAVA文件中获取路径及WEB应用程序获取路径方法 1. 基本概念的理解 `绝对路径`:你应用上的文件或目录在硬盘上真正的路径,如:URL.物理路径 例如: c:/xyz/test.txt代表了test.txt文件的绝对路径: http://www.sun.com/index.htm也代表了一个URL绝对路径: `相对路径`:相对与某个基准目录的路径,包含Web的相对路径(HTML中的相对目录). 例如: 在Servlet中,"/"代表Web应用的根目录,和物理路径的相对表示. 例如:…
Java中获取文件路径 1.实例说明 (1)得到 ClassPath的绝对URI路径 Thread.currentThread().getContextClassLoader().getResource(".").getPath(); (2)得到 ClassPath的绝对URI路径 Thread.currentThread().getContextClassLoader().getResource("").getPath(); (3)得到工程的路径 System.g…