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

georgedatacenter39美元/月$20/年/洛杉矶独立服务器美国VPS/可选洛杉矶/芝加哥/纽约/达拉斯机房/

georgedatacenter这次其实是两个促销,一是促销一款特价洛杉矶E3-1220 V5独服,性价比其实最高;另外还促销三款特价vps,georgedatacenter是一家成立于2019年的美国VPS商家,主营美国洛杉矶、芝加哥、达拉斯、新泽西、西雅图机房的VPS、邮件服务器和托管独立服务器业务。georgedatacenter的VPS采用KVM和VMware虚拟化,可以选择windows...

百纵科技,美国独立服务器 E52670*1 32G 50M 200G防御 899元/月

百纵科技:美国高防服务器,洛杉矶C3机房 独家接入zenlayer清洗 带金盾硬防,CPU全系列E52670、E52680v3 DDR4内存 三星固态盘阵列!带宽接入了cn2/bgp线路,速度快,无需备案,非常适合国内外用户群体的外贸、搭建网站等用途。C3机房,双程CN2线路,默认200G高防,3+1(高防IP),不限流量,季付送带宽美国洛杉矶C3机房套餐处理器内存硬盘IP数带宽线路防御价格/月套...

CloudCone:洛杉矶MC机房KVM月付1.99美元起,支持支付宝/PayPal

CloudCone是一家成立于2017年的国外VPS主机商,提供独立服务器租用和VPS主机,其中VPS基于KVM架构,多个不同系列,譬如常规VPS、大硬盘VPS等等,数据中心在洛杉矶MC机房。商家2021年Flash Sale活动继续,最低每月1.99美元,支持7天退款到账户,支持使用PayPal或者支付宝付款,先充值后下单的方式。下面列出几款VPS主机配置信息。CPU:1core内存:768MB...

java获取服务器路径为你推荐
融360我想申请(融360)贷款5万元,一年得付多少利息?连接池什么叫做“连接池机制”按键精灵教程按键精灵怎么使用fast路由器路由器fast怎么设置无线网络短信应用Android手机短信应用都有哪些?教育城域网教育城域网的教育城域网的用途光纤是什么什么是光纤.是什么材料做的?阿里下载最新阿里旺旺怎么下载4g上网卡4G手机上网卡和4G网络是什么意思?快照优化快照跟不上优化节奏优化方法出问题?
绍兴服务器租用 山东vps 播放vps上的视频 lamp安装 网站保姆 php免费空间 绍兴高防 骨干网络 上海域名 秒杀预告 谁的qq空间最好看 135邮箱 怎么建立邮箱 江苏双线服务器 国内域名 atom处理器 lamp怎么读 lamp架构 lamp兄弟连 稳定空间 更多