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

修罗云50元/月起香港大宽带NAT VPS,香港沙田建站2核2G5M仅70元/月起

修罗云怎么样?修罗云是一家国内老牌商家,修罗云商家以销售NAT机器起家,国内的中转机相当不错,给的带宽都非常高,此前推荐的也都是国内NAT VPS机器。今天,云服务器网(www.yuntue.com)小编主要介绍一下修罗云的香港云服务器,适合建站,香港沙田cn2云服务器,2核2G,5M带宽仅70元/月起,同时香港香港大带宽NAT VPS低至50元/月起,性价比不错,可以尝试一下!点击进入:修罗云官...

AkkoCloud(60元/月 ),英国伦敦CN2 1核 768 MB 内存 10 GB SSD 硬盘 600GB 流量 英国伦敦CN2 1核  1.5G  300Mbps

官方网站:https://www.akkocloud.com/AkkoCloud新品英国伦敦CN2 GIA已上线三网回程CN2 GIA 国内速度优秀.电信去程CN2 GIALooking Glass:http://lonlg.akkocloud.com/Speedtest:http://lonlg.akkocloud.com/speedtest/新品上线刚好碰上国庆节 特此放上国庆专属九折循环优惠...

弘速云香港VPSVPS线路有CN2+BGP、CN2 GIA,KVM虚拟化架构,裸金属月付564元

弘速云怎么样?弘速云是创建于2021年的品牌,运营该品牌的公司HOSU LIMITED(中文名称弘速科技有限公司)公司成立于2021年国内公司注册于2019年。HOSU LIMITED主要从事出售香港vps、美国VPS、香港独立服务器、香港站群服务器等,目前在售VPS线路有CN2+BGP、CN2 GIA,该公司旗下产品均采用KVM虚拟化架构。可联系商家代安装iso系统。点击进入:弘速云官方网站地址...

java获取服务器路径为你推荐
企业无线覆盖方案厂房该如何搭建网络和WiFi覆盖重装系统后数据恢复重装系统后文件丢失如何恢复求答案swift语言苹果为什么要推出swift语言开发者账号如何免费申请开发者账号光纤是什么什么是光纤.是什么材料做的?站内搜索引擎站内搜索与百度的搜索引擎有什么本质性的区别?哪些大数据公司提供站内搜索这种服务?网络图绘制双代号网络图的绘制方法?摇一摇周边微信摇一摇周边红包设置我的电脑打开很慢电脑开机慢怎么办电脑速度慢怎么办警告本网站内容如何去掉安全警告提示,是否只查看安全传送的网页内容
北京租服务器 国外idc permitrootlogin 大容量存储 免费smtp服务器 最好的空间 howfile bgp双线 umax120 1美金 太原联通测速 web应用服务器 免费的域名 photobucket 免费蓝钻 大化网 cpu使用率过高怎么办 server2008 认证机构 带宽测速 更多