file.getPath() getAbsolutePath() getCanonicalPath()区别
2016-06-07 18:21
543 查看
package file; import java.io.File; import java.io.IOException; public class getFilePath { public static void main(String[] args) throws IOException { System.out.println("------默认相对路径,取得路径不同-----"); File f = new File("..\\src\\file"); System.out.println(f.getPath()); System.out.println(f.getAbsolutePath()); System.out.println(f.getCanonicalPath()); System.out.println("------默认相对路径,取得路径不同-----"); File f2 = new File(".\\src\\file"); System.out.println(f2.getPath()); System.out.println(f2.getAbsolutePath()); System.out.println(f2.getCanonicalPath()); System.out.println("------默认绝对路径,取得路径相同-----"); File f3 = new File("C:\\src\\file"); System.out.println(f3.getPath()); System.out.println(f3.getAbsolutePath()); System.out.println(f3.getCanonicalPath()); // 执行结果为: // ------默认相对路径,取得路径不同----- // ..\src\file // C:\workspace\Tip\..\src\file // C:\workspace\src\file // ------默认相对路径,取得路径不同----- // .\src\file // C:\workspace\Tip\.\src\file // C:\workspace\Tip\src\file // ------默认绝对路径,取得路径相同----- // C:\src\file // C:\src\file // C:\src\file // // 比较可以得到 // getPath()返回的是构造方法里的路径,构造方法给的string是什么就是什么不做任何处理 // getAbsolutePath()返回的是 user.dir+getPath(),也就是工程路径加上构造方法中的路径 // getCanonicalPath()返回的是将符号完全解析的路径,也就是全路径。会进行上级目录计算。 } }
相关文章推荐
- php实现文件下载
- urlencode
- php global 的用法
- PHP获取当前服务器信息的基本语句
- PHP内核研究(内存管理1)
- php cURL library is not loaded
- win2008 iis7/iis7.5下最简单最强安装多版本PHP支持环境
- TP框架下 xml_encode的用法
- mac下得matplotlib配置
- 【php学习】图片处理三步走
- HDOJ 1091 A+B for Input-Output Practice (III)
- PHP开发知识
- 使用matplotlib的示例:调整字体-设置刻度、坐标、colormap和colorbar等
- 配置FTP服务器提供上传下载功能
- PHP中is_file,file_exists的区别,is_file 不能替代file_exits的理由
- PHP中提供的用于MySQL的主要API是什么?(官网整理)
- PHP 获取IP 相关
- Yii2 验证码
- PHP-表单
- Windows 2008 R2 下IIS7.5+PHP5.2环境配置(FastCgi设置)