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(); //得到的是..

CloudCone($82/月)15-100M不限流量,洛杉矶CN2 GIA线路服务器

之前分享过很多次CloudCone的信息,主要是VPS主机,其实商家也提供独立服务器租用,同样在洛杉矶MC机房,分为两种线路:普通优化线路及CN2 GIA,今天来分享下商家的CN2 GIA线路独立服务器产品,提供15-100Mbps带宽,不限制流量,可购买额外的DDoS高防IP,最低每月82美元起,支持使用PayPal或者支付宝等付款方式。下面分享几款洛杉矶CN2 GIA线路独立服务器配置信息。配...

美国云服务器 1核 1G 30M 50元/季 兆赫云

【双十二】兆赫云:全场vps季付六折优惠,低至50元/季,1H/1G/30M/20G数据盘/500G流量/洛杉矶联通9929商家简介:兆赫云是一家国人商家,成立2020年,主要业务是美西洛杉矶联通9929线路VPS,提供虚拟主机、VPS和独立服务器。VPS采用KVM虚拟架构,线路优质,延迟低,稳定性强。是不是觉得黑五折扣力度不够大?还在犹豫徘徊中?这次为了提前庆祝双十二,特价推出全场季付六折优惠。...

GeorgeDatacenter:洛杉矶/达拉斯/芝加哥/纽约vps云服务器;2核/8GB/250GB/2TB流量/1Gbps端口,$84/年

georgedatacenter怎么样?GeorgeDatacenter是一家2017年成立的美国商家,正规注册公司(REG: 10327625611),其实是oneman。现在有优惠,有几款特价VPS,基于Vmware。支持Paypal付款。GeorgeDatacenter目前推出的一款美国vps,2核/8GB内存/250GB NVMe空间/2TB流量/1Gbps端口/Vmware/洛杉矶/达拉...

java获取服务器路径为你推荐
descriptionDescription是什么意思?信件格式写书信的格式图片教育城域网关于学校局域网文件下载burndownburn down是否及物?能用被动语态吗?约束是什么意思约束,是什么意思。如有回答,请详细,怎样上传照片如何上传照片警告本网站内容IE浏览器为什么登入一些网站会出现安全警告"是否只查看安全传送的网页内容"?安全网络攻防大赛安全知识竞赛硬盘文件不显示硬盘文件看不到 但文件还存在硬盘文件不显示我的电脑的D,E,F硬盘里面的文件夹不显示了,怎么才能显示出来?
x3220 全球付 缓存服务器 gomezpeer 好看的留言 建站代码 e蜗 hostloc isp服务商 微软服务器操作系统 raid10 联通网站 中国电信测速器 湖南idc 华为k3 广州主机托管 hdsky 酷锐 magento主机 cloudflare 更多