Blog信息 |
blog名称:小鸟吹烟 日志总数:157 评论数量:424 留言数量:-1 访问次数:1258108 建立时间:2006年10月23日 |

| |
[J2SE]取文件路径 软件技术
tone 发表于 2008/6/17 14:34:37 |
1.CommonTool.class.getClassLoader().getResource("NE.txt").getPath()
2. Properties temp = new Properties(); temp.load(CommonFunction.class.getClassLoader().getResourceAsStream ("FoundIndex.properties"));
3.Resource resource = new ClassPathResource("workTime.xml"); System.out.println( resource.getFile().getPath() );
4. //取当前路径 import java.util.Properties; Properties properties = System.getProperties(); System.out.println(properties.getProperty("user.dir")); //jsp取启动路径 String dir = application.getRealPath("/"); String path =ClassLoader.getSystemClassLoader().getResource("Res/ITNMprj.exe").getPath();
5.
** * 在JAVA后台取文件路径 *///取根的绝对路径URL basePath = Thread.currentThread().getContextClassLoader().getResource("");//取相对路径String realPath = new File(basePath.getFile(),"../../" + url).getCanonicalPath();//转换空格realPath = URLDecoder.decode(realPath,"utf-8");//打开文件InputStream is = new FileInputStream(realPath);
/** * 在Servlet中取路径 */ServletContext application = this.getServletConfig().getServletContext();String filePath = context.getResource(url).toString();InputStream is = new java.net.URL(filePath).openStream();
/** |
|
|