java获取路径的方法】的更多相关文章

1.利用System.getProperty()函数获取当前路径: System.getProperty("user.dir");//user.dir用户当前的工作目录,输出:D:\开发工程\GitHub\5_java_example\uritest\application,(如果想要通过此方法获取其它系统信息,参考:http://www.cnblogs.com/EasonJim/p/6507672.html) 注意:以上输出为eclipse的application的输出. 测试JAR…
package com.zjf; import java.io.File; public class GetPath { public static void getPath() { //方式一 System.out.println(System.getProperty("user.dir")); //方式二 File directory = new File("");//设定为当前文件夹 try{ System.out.println(directory.getC…
(1).request.getRealPath("/");//不推荐使用获取工程的根路径 (2).request.getRealPath(request.getRequestURI());//获取jsp的路径,这个方法比较好用,可以直接在servlet和jsp中使用 (3).request.getSession().getServletContext().getRealPath("/");//获取工程的根路径,这个方法比较好用,可以直接在servlet和jsp中使用…
就目前的我来说最常用的两种获取路径的方法是  class.getRecource(filename) 和 class.getclassloader.getRecource(filename) 这两者的区别其实很简单就是路径的时候有点不同,这里主要讲两个参数,其他的路径获取,其他的话在根据相对路径逐一查找就行了 class.getRecource(filename): 参数"/" 表示获取根目录; (即我们常用到的bin目录[字节码文件存放的目录] " "  表示获取…
(1).request.getRealPath("/");//不推荐使用获取工程的根路径 (2).request.getRealPath(request.getRequestURI());//获取jsp的路径,这个方法比较好用,可以直接在servlet和jsp中使用 (3).request.getSession().getServletContext().getRealPath("/");//获取工程的根路径,这个方法比较好用,可以直接在servlet和jsp中使用…
Java Web开发中路径问题小结 (1) Web开发中路径的几个基本概念 假设在浏览器中访问了如下的页面,如图1所示: 那么针对这个站点的几个基本概念表述如下: 1. web站点的根目录:http://localhost:8080/ 2. web应用程序的的根目录:http://localhost:8080/test/ 3.同级目录:http://localhost:8080/test/articles/article1.jsp和http://localhost:8080/test/artic…
转载只供个人学习参考,查看请前往原出处:http://www.cnblogs.com/guoyuqiangf8/p/3506768.html 主要方法有: (1).request.getRealPath("/");             //不推荐使用获取工程的根路径(2).request.getRealPath(request.getRequestURI());         //获取jsp的路径,这个方法比较好用,可以直接在servlet和jsp中使用(3).request.g…
在class获取路径的方法,getResource有没有“\”的区别 System.out.println("" + this.getClass().getResource("").getPath()); video/software/JavaWorkspace/java_web_test/out/artifacts/java_web_test_war_exploded/WEB-INF/classes/cn/xx/dao/ System.out.println(&q…
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 在Android4.4之前和之后,通过Intent调用文件管理器选择文件,获取的文件uri地址形式是不同的. Android6.0 content://com.android.providers.media.documents/document/image%3A593410 Android4.2.2 file:///storage/emulated/0/Pictures/Screenshots/Screenshot_2017-0…
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()…
原文:[转载]ASP.NET获取路径的方法 HttpContext.Current.Request.PhysicalPath;    // 获得当前页面的完整物理路径.比如 F:\XFU.NSQS\project\website\Default.aspxHttpContext.Current.Request.PhysicalApplicationPath; // 获得当前程序运行的物理路径比 如F:\XFU.NSQS\project\website\HttpContext.Current.Ser…
目前Java获取文件大小的方法有两种: 1.通过file的length()方法获取: 2.通过流式方法获取: 通过流式方法又有两种,分别是旧的java.io.*中FileInputStream的available()方法和新的java..nio.*中的FileChannel 下面依次介绍这几种方法: 首先选择一个文件并查看这个文件在windows中显示的大小,为了测试准确性,我这里选取了一个大文件(超过2GB) 查看这个文件在windows中显示的大小: 使用在线转换工具将其转换成字节: 可以看…
Java获取路径中的文件名(正则表达式) 目标 在这个路径中我想得到model2 /E:/2017-02-21--SoftWare/github/test/Java/poiDemo_word2excel/target/test-classes/model2.docx 操作 String srcFile="/E:/2017-02-21--SoftWare/github/test/Java/poiDemo_word2excel/target/test-classes/model2.docx"…
java获取调用当前方法的方法名和行数String className = Thread.currentThread().getStackTrace()[2].getClassName();//调用的类名 String methodName = Thread.currentThread().getStackTrace()[2].getMethodName();//调用的方法名 int lineNumber = Thread.currentThread().getStackTrace()[2].g…
下面1-4的内容是网上收集的相关知识,总结来说,就是如下几个知识点: 最常用读取properties文件的方法 InputStream in = getClass().getResourceAsStream("资源Name");这种方式要求properties文件和当前类在同一文件夹下面.如果在不同的包中,必须使用: InputStream ins = this.getClass().getResourceAsStream("/cn/zhao/properties/testP…
模拟器的位置: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs   文档安装位置: /Applications/Xcode.app/Contents/Developer/Documentation/DocSets   插件保存路径: ~/Library/ApplicationSupport/Developer/Shared/Xcode/Plug-ins   自…
JAVA 获取当前月的初始时间的时间戳 public static long getMonthFirstDay() { Calendar calendar = Calendar.getInstance();// 获取当前日期 calendar.add(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天 calendar.set(Calendar.HOUR_OF_DAY, 0); calen…
1.获取当前类所在的“项目名路径” String rootPath = System.getProperty("user.dir"); 2.获取编译文件“jar包路径”(反射) System.out.println(类名.class.getClassLoader().getResource("文件名/文件夹")); System.out.println(System.getProperty("java.class.path")); InputSt…
资源文件放在哪里? 上 图中的 resources 目录叫资源目录 (main下,与java如果没有请自行创建), 在项目编译后文件会被放到红色的 classes 目录下, 注意如果你的 resources 目录没有上图的那个金色资源目录图标, 请再 idea 上右键该目录选择 Mark directory as - Resources Root, 这样, 在项目编译以后, 你的资源就会放到编译目录下. 如何获得这些文件? 当资源文件被编译到编译目录下以后, 我们可以通过 Class.getRe…
1.System.getProperty("user.dir") 函数获取当前路径 // 获取当前路径方式1 System.out.println(System.getProperty("user.dir")); String filePath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "com"…
Environment 常用方法: * 方法:getDataDirectory()解释:返回 File ,获取 Android 数据目录.* 方法:getDownloadCacheDirectory()解释:返回 File ,获取 Android 下载/缓存内容目录.* 方法:getExternalStorageDirectory()解释:返回 File ,获取外部存储目录即 SDCard* 方法:getExternalStoragePublicDirectory(String type)解释:…
当我们选择图片以后,返回的是Uri,此时我们要把路径存储到数据库,必须将其转换成String类型. URI:  //content://com.android.providers.media.documents/document/image%3A255779 转换后的路径:/storage/emulated/0/DCIM/Camera/IMG_20160117_132926.jpg 转换的方法:getPath import android.annotation.SuppressLint; imp…
1.利用System.getProperty()函数获取当前路径:System.out.println(System.getProperty("user.dir"));//user.dir指定了当前的路径 2.使用File提供的函数获取当前路径:File directory = new File("");//设定为当前文件夹try{    System.out.println(directory.getCanonicalPath());//获取标准的路径    Sy…
1.利用System.getProperty()函数获取当前路径:System.out.println(System.getProperty("user.dir"));//user.dir指定了当前的路径 2.使用File提供的函数获取当前路径:File directory = new File("");//设定为当前文件夹try{    System.out.println(directory.getCanonicalPath());//获取标准的路径    Sy…
方法一: (数据类型)(最小值 + Math.random()*(最大值-最小值+1) ); 示例: (int)(1+Math.random()*(10-1+1)): 获取int类型 1-10的随机数 int max=10; int min =1; for (int i=0;i<10;i++){ System.out.println( (int)(min+Math.random()*(max-min+1)) ); } 结果: 方法二: 通过java.Math包的random方法得到1-10的in…
HttpContext.Current.Request.PhysicalPath;    // 获得当前页面的完整物理路径.比如 F:\XFU.NSQS\project\website\Default.aspxHttpContext.Current.Request.PhysicalApplicationPath; // 获得当前程序运行的物理路径比 如F:\XFU.NSQS\project\website\HttpContext.Current.Server.MapPath(@"\")…
1.获取WEB-INF文件夹下的文件 /C:/Users/Administrator/Workspaces/MyEclipse%2010/day_38_spring_hibernate/WebRoot/WEB-INF/classes/com/itheima/test/ String path=TestHibernate.class.getResource("").getPath(); System.out.println(path); 其对应的文件位置是 2.获取WEB-INF文件夹下…
package com.zhi.test; public class PathTest { public static void main(String[] args) { System.out.println(PathTest.class.getResource("")); System.out.println(PathTest.class.getResource("/")); System.out.println(PathTest.class.getClassL…
Environment常用方法: getExternalStrongeDirectory() 返回File,获取外部存储目录即SDCard getDownloadCacheDirectory() 返回 File ,获取 Android 下载/缓存内容目录. getDataDirectory() 返回 File ,获取 Android 数据目录. getExternalStorageState() 返回 File ,获取外部存储设备的当前状态 getRootDirectory() 返回 File…
很简单,直接看代码: public void showClassAndMethod() { System.out.println(this.getClass().getSimpleName() + ":" + new Exception().getStackTrace()[0].getMethodName()); }…