关于获取路径path
String webPath = request.getServletPath();
log.info(webPath);
输出:
/zjdlbb/zjdlbb/zjdlbb/test.ht
log.info(request.getServletContext().getRealPath("/"));
输出:
E:\Program Files (x86)\workspace\oms\web\
String webPath = request.getContextPath();
log.info(webPath);
输出:/oms
// 使用相对目录的方式读取文件,相对目录即是项目的目录
File file = new File("src" + File.separator + "dom"
+ File.separator + "xml" + File.separator + "class.xml");
File file2 = new File(DomDemo.class.getClassLoader()
.getResource("").getPath().substring(1)
+ "dom"
+ File.separator
+ "xml"
+ File.separator
+ "class.xml");
//当前路径
System.out.println(Demo01.class.getResource("."));// file:/D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/demo01/
System.out.println(Demo01.class.getResource(""));// file:/D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/demo01/
System.out.println(Demo01.class.getResource(".").getPath());// /D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/demo01/
System.out.println(Demo01.class.getResource("").getPath());// /D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/demo01/
//根目录
System.out.println(Demo01.class.getResource("/"));// file:/D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/
System.out.println(Demo01.class.getResource("/").getPath());// /D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/
//项目路径
System.out.println(System.getProperty("user.dir"));// D:\Program\workspace\freemarker
System.out.println(Demo01.class.getClassLoader().getResource("."));// file:/D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/
System.out.println(Demo01.class.getClassLoader().getResource(""));// file:/D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/
System.out.println(Demo01.class.getClassLoader().getResource(".").getPath());// /D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/
System.out.println(Demo01.class.getClassLoader().getResource("").getPath());// /D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/
关于获取路径path的更多相关文章
- 获取路径path
request 的常用方法 request.getSchema() 返回当前页面使用的协议,http 或是 https; request.getServerName() 返回当前页面所在的服务器的名字 ...
- Android根据图片Uri获取图片path绝对路径的几种方法【转】
在Android 编程中经常会用到Uri转化为文件路径,如我们从相册选择图片上传至服务器,一般上传前需要对图片进行压缩,这时候就要用到图片的绝对路径. 下面对我开发中uri转path路径遇到的问题进行 ...
- java中获取路径的几种基本的方法
package com.ygh.blog.realpath; import java.io.File; import java.io.IOException; import java.io.Input ...
- JavaEE 获取路径全攻略
本篇博客是 JavaWeb 应用服务器端在不同环境下获取文件路径的全面总结. 获取文件路径后主要应用的场景,读取 JavaWeb 自定义配置文件.在特定路径下生成各种类型的文件提供下载...... 想 ...
- C#项目打开/保存文件夹/指定类型文件,获取路径
C#项目打开/保存文件夹/指定类型文件,获取路径 转:http://q1q2q363.xiaoxiang.blog.163.com/blog/static/1106963682011722424325 ...
- find_first_of()和 find_last_of() 【获取路径、文件名】
find_first_of()和 find_last_of() [获取路径.文件名](2011-06-11 12:44:46)转载▼标签: 杂谈 分类: c string 类提供字符串处理函数,利用 ...
- Java文件获取路径方式:
转自:http://blog.csdn.net/appleprince88/article/details/11599805# 谢谢! 由于经常需要获取文件的路径,但是比较容易忘记,每次需要总需要查询 ...
- Java获取路径方法&相对路径读取xml文件方法
(1).request.getRealPath("/");//不推荐使用获取工程的根路径 (2).request.getRealPath(request.getRequestURI ...
- java中获取路径中的空格处理(%20)问题
在java中获取文件路径的时候,有时候会获取到空格,但是在中文编码环境下,空格会变成“%20”从而使得路径错误. 解决办法: String path = Parameter.class.getReso ...
随机推荐
- 【ArcGIS】栅格分析-问题之001(转)
在arcgis中进行栅格计算时,碰到这样的错误ERROR 000539:Error running expression:rcexec()<type 'exceptions.ValueError ...
- postmain 通过函数动态设置参数
调用服务器的服务,其中有个参数是签名,签名需要计算,需要写一个本地函数. 下一步 pre-request Script 的代码如下: (function($) { if(!$.encoding) $. ...
- ansj分词原理
ansj第一步会进行原子切分和全切分,并且是在同时进行的.所谓原子,是指短句中不可分割的最小语素单位.例如,一个汉字就是一个原子.全切分,就是把一句话中的所有词都找出来,只要是字典中有的就找出来.例如 ...
- day_6.9py网络编程
.路由器:能够链接不同的网络使他们之间能够通信 mac就是手拉手传输数据用的
- mysql中将查询结果进行拼接处理及concat、group_concat的使用
说明: 本文中使用的例子均在下面的数据库表tt2下执行: 一.concat()函数1.功能:将多个字符串连接成一个字符串. 2.语法:concat(str1, str2,...) 返回结果为连接参数产 ...
- 在Ubuntu上安装Chrome Driver和Firefox Driver
在Ubuntu上安装Chrome Driver和Firefox Driver 此文章只介绍Chrome Driver(Firefox Driver和该步骤相同) 下载链接:http://chromed ...
- VS没办法调试,直接退出,报错:1. 使用调试生成配置或禁用调试选项“启用‘仅我的代码’”。。。
打开一个Demo,结果没办法调试,运行出错,直接退出了, 明明加了断点的. 输出→调试→提示信息如下 . 使用调试生成配置或禁用调试选项“启用‘仅我的代码’”. . 检查调试选项下的“符号”设置.线程 ...
- POJ 1488 - TEX Quotes
Description TEX is a typesetting language developed by Donald Knuth. It takes source text together w ...
- tensorRT 构建推理引擎
- hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion
http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不 ...