java获取服务器路径JAVA怎样获取当前路径

java获取服务器路径  时间:2021-09-18  阅读:()

java 怎么获取web根目录

以工程名为TEST为例: (1)得到包含工程名的当前页面全路径:request.getRequestURI() 结果:/TEST/test.jsp (2)得到工程名:request.getContextPath() 结果:/TEST (3)得到当前页面所在目录下全名称:request.getServletPath() 结果:如果页面在jsp目录下 /TEST/jsp/test.jsp (4)得到页面所在服务器的全路径:application.getRealPath("页面.jsp") 结果:D:/resin/webapps/TEST/test.jsp (5)得到页面所在服务器的绝对路径:absPath=new java.io.File(application.getRealPath(request.getRequestURI())).getParent(); 结果:D:/resin/webapps/TEST 2.在类中取得路径: (1)类的绝对路径:String u=Class.class.getClass().getResource("/").getPath() 结果:/D:/TEST/WebRoot/WEB-INF/classes/pack/ (2)得到工程的路径:System.getProperty("user.dir") 结果:D:/TEST 3.在Servlet中取得路径: (1)得到工程目录:request.getSession().getServletContext().getRealPath("") 参数可具体到包名。

结果:E:/Tomcat/webapps/TEST (2)得到IE地址栏地址:request.getRequestURL() 结果:http://localhost:8080/TEST/test (3)得到相对地址:request.getRequestURI() 结果:/TEST/test

java中获取文件路径的几种方式

获取当前类的所在工程路径; 如果不加“/” File f = new File(this.getClass().getResource("").getPath()); System.out.println(f);结果:C:Documents%20and%20SettingsAdministratorworkspaceprojectName\test 获取当前类的绝对路径;第二种:File directory = new File("");//参数为空 String courseFile = directory.getCanonicalPath() ; System.out.println(courseFile);结果:C:Documents and SettingsAdministratorworkspaceprojectName 获取当前类的所在工程路径;第三种:URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt"); System.out.println(xmlpath);结果:file:/C:/Documents%20and%20Settings/Administrator/workspace/projectName/bin/selected.txt 获取当前工程src目录下selected.txt文件的路径第四种:System.out.println(System.getProperty("user.dir"));结果:C:Documents and SettingsAdministratorworkspaceprojectName 获取当前工程路径第五种:System.out.println( System.getProperty("java.class.path"));结果:C:Documents and SettingsAdministratorworkspaceprojectNamein获取当前工程路径

如何java获取路径?`

可以的 采用 File 类 和 FileFilter 接口: public static void main(String args[]){ File directory = new File("/conf/sechand/naalee/"); System.out.println(directory.isDirectory()); File[] fileList = directory.listFiles(new java.io.FileFilter() { public boolean ept(File file) { if(file.getName().endsWith(".conf")) return true; else return false; }}); for (File file : fileList) { System.out.println(file.getPath()); } }

JAVA怎样获取当前路径

java获取当前路径的几种方法 1、利用System.getProperty()函数获取当前路径: System.out.println(System.getProperty("user.dir"));//user.dir指定了当前的路径 2、使用File提供的函数获取当前路径: File directory = new File("");//设定为当前文件夹 try{ System.out.println(directory.getCanonicalPath());//获取标准的路径 System.out.println(directory.getAbsolutePath());//获取绝对路径 }catch(Exceptin e){} File.getCanonicalPath()和File.getAbsolutePath()大约只是对于new File(".")和new File("..")两种路径有所区别。

# 对于getCanonicalPath()函数,“."就表示当前的文件夹,而”..“则表示当前文件夹的上一级文件夹 # 对于getAbsolutePath()函数,则不管”.”、“..”,返回当前的路径加上你在new File()时设定的路径 # 至于getPath()函数,得到的只是你在new File()时设定的路径 比如当前的路径为 C:/test : File directory = new File("abc"); directory.getCanonicalPath(); //得到的是C:/test/abc directory.getAbsolutePath(); //得到的是C:/test/abc direcotry.getPath(); //得到的是abc File directory = new File("."); directory.getCanonicalPath(); //得到的是C:/test directory.getAbsolutePath(); //得到的是C:/test/. direcotry.getPath(); //得到的是. File directory = new File(".."); directory.getCanonicalPath(); //得到的是C:/ directory.getAbsolutePath(); //得到的是C:/test/.. direcotry.getPath(); //得到的是..

阿里云香港 16核32G 20M 999元/月

阿里云香港配置图提速啦是成立于2012年的十分老牌的一个商家这次给大家评测的是 阿里云香港 16核32G 20M 这款产品,单单说价格上就是十分的离谱原价8631元/月的现价只要 999元 而且还有个8折循环优惠。废话不多说直接进入正题。优惠时间 2021年8月20日-2021年9月20日 优惠码 wn789 8折优惠阿里云香港BGP专线 16核32G 10M带宽 优惠购买 399元购买链接阿里云...

轻云互联(19元)香港高防云服务器 ,美国云服务器

轻云互联成立于2018年的国人商家,广州轻云互联网络科技有限公司旗下品牌,主要从事VPS、虚拟主机等云计算产品业务,适合建站、新手上车的值得选择,香港三网直连(电信CN2GIA联通移动CN2直连);美国圣何塞(回程三网CN2GIA)线路,所有产品均采用KVM虚拟技术架构,高效售后保障,稳定多年,高性能可用,网络优质,为您的业务保驾护航。活动规则:用户购买任意全区域云服务器月付以上享受免费更换IP服...

易探云服务器怎么过户/转让?云服务器PUSH实操步骤

易探云服务器怎么过户/转让?易探云支持云服务器PUSH功能,该功能可将云服务器过户给指定用户。可带价PUSH,收到PUSH请求的用户在接收云服务器的同时,系统会扣除接收方的款项,同时扣除相关手续费,然后将款项打到发送方的账户下。易探云“PUSH服务器”的这一功能,可以让用户将闲置云服务器转让给更多需要购买的用户!易探云服务器怎么过户/PUSH?1.PUSH双方必须为认证用户:2.买家未接收前,卖家...

java获取服务器路径为你推荐
技术文档管理公司技术部文件集中管理如何操作?连接池数据库连接池的原理是什么?xhtml请问XHTML是什么东西?一般在什么情况下使用的?小项目现在有什么好的小项目可以做啊光纤是什么什么是光纤.是什么材料做的?antiarp360防火墙:antiarp.exe文件损坏.运行chkdsk是什么意思?怎么处理?摇一摇周边微信摇一摇周边红包设置soap是什么意思rbq是什么意思?sd卡座SD卡座 FPC座子请问这些产品哪家厂家的货比较好啊?约束是什么意思约束,是什么意思。如有回答,请详细,
域名批量查询 Oray域名注册服务商 云南服务器租用 域名服务器上存放着internet主机的 泛域名解析 a5域名交易 冰山互联 highfrequency wavecom hnyd 新家坡 腾讯实名认证中心 国外代理服务器软件 网络空间租赁 服务器干什么用的 吉林铁通 drupal安装 阿里云官方网站 西安主机 photobucket 更多