Java中getAbsolutePath()实例详解
来源:互联网 发布:mac word 导航栏 编辑:程序博客网 时间:2024/06/09 21:15
参考下面的实例,你就可以更清楚的理解“getabsolutepath():”的用处了。
getAbsolutePath():返回抽象路径名的绝对路径名字符串。
public static void test1(){
File file1 = new File(".\\test1.txt");
File file2 = new File("D:\\workspace\\test\\test1.txt");
System.out.println("-----默认相对路径:取得路径不同------");
System.out.println(file1.getPath());
System.out.println(file1.getAbsolutePath());
System.out.println("-----默认绝对路径:取得路径相同------");
System.out.println(file2.getPath());
System.out.println(file2.getAbsolutePath());
}
-----默认相对路径:取得路径不同------
.\test1.txt
D:\workspace\test\.\test1.txt
-----默认绝对路径:取得路径相同------
D:\workspace\test\test1.txt
D:\workspace\test\test1.txt
----------------------------------------------------
public static void test2() throws Exception{
File file = new File("..\\src\\test1.txt");
System.out.println(file.getAbsolutePath());
System.out.println(file.getCanonicalPath());
}
D:\workspace\test\..\src\test1.txt
D:\workspace\src\test1.txt
--------------------------------------------
public static void test3() throws Exception{
File file = new File("D:\\Text.txt");
System.out.println(file.getCanonicalPath());
}
(1),确定D盘下没有Text.txt这个文件,直接执行这段代码,得到的结果是:
D:\Text.txt注意这里试大写的Text.txt
(2)在D盘下建立一个文件,名叫text.txt,再次执行代码,得到结果
D:\text.txt同样的代码得到不同的结果。
(3)获取文件的绝对路径。如得到:“E:\workspace\test\file1.txt”.
(3)获取文件的绝对路径。如得到:“E:\workspace\test\file1.txt”.
原文:http://www.software8.co/wzjs/java/1791.html
- Java中getAbsolutePath()实例详解
- 【java】getAbsolutePath()方法详解
- 【java】getAbsolutePath()方法详解
- Java中getAbsolutePath()什么意思?
- java中getpath、getabsolutepath和getname
- Java中getPath与getAbsolutePath区别
- JAVA中file的getPath getAbsolutePath和getCanonicalPath的不同
- Java 中 File.getPath() getAbsolutePath()和getCanonicalPath()的不同
- Java中file类getPath(),getAbsolutePath(),getCanonicalPath()方法区别
- Java中file类getPath(),getAbsolutePath(),getCanonicalPath()方法区别
- java中File类的getPath(),getAbsolutePath(),getCanonicalPath()区别
- Java中file类getPath(),getAbsolutePath(),getCanonicalPath()方法区别
- java中file的getPath(),getAbsolutePath(),getCanonicalPath()的比较
- java中File类的getPath(),getAbsolutePath(),getCanonicalPath()区别
- Java中File的getAbsolutePath()包含文件的名称
- java中File类的getPath(),getAbsolutePath(),getCanonicalPath()区别
- java中File类的getPath(),getAbsolutePath(),getCanonicalPath()区别
- java中File类的getPath(),getAbsolutePath(),getCanonicalPath()区别
- Invoke和BeginInvoke实例详解
- 字符编码之间的转换
- android 游戏导引(1. 建立 OpenGL 项目)
- CyclicBarrier介绍
- Struts上传文件技术
- Java中getAbsolutePath()实例详解
- 快捷配置Log4J打印到控制台
- 苏宁面试(二)
- <iOS>网络编程(一)SOAP, WSDL, Web Service
- Tomcat在Bin目录中启动需要配置的信息
- 网站架构学习笔记之知识点索引
- Sun One Directory Server(LDAP)安装和调整指南
- Redis的安装及使用
- android 游戏导引(2. 游戏的基础设置)