怎样推广网站平台,优化工作流程,网上注册公司流程和费用营业执照,国外网站域名1.getAbsolutePath() 得到绝对路径、全路径。 getpath() 得到缩写的路径#xff0c;根据当前目录位置可以缩写路径。得到相对路径。 getCanonicalPath() 得到标准路径#xff0c;将统一平台间的路径写法差异。 File的这三个方法在api中都有说明#xff0c;仅以程序为例说明。…1.getAbsolutePath() 得到绝对路径、全路径。 getpath() 得到缩写的路径根据当前目录位置可以缩写路径。得到相对路径。 getCanonicalPath() 得到标准路径将统一平台间的路径写法差异。 File的这三个方法在api中都有说明仅以程序为例说明。 package test; import java.io.File; import java.io.IOException; public class TestFilePath { public static void main(String[] args) { // TODO Auto-generated methodstub System.out.println(System.getProperty(user.dir)); try { System.out.println(-----默认相对路径取得路径不同------); File file1 new File(..\\src\\test1.txt); System.out.println( file1.getPath()); System.out.println( file1.getAbsolutePath()); System.out.println(file1.getCanonicalPath()); System.out.println(-----默认相对路径取得路径不同------); File file new File(.\\test1.txt); System.out.println(file.getPath()); System.out.println(file.getAbsolutePath()); System.out.println(file.getCanonicalPath()); System.out.println(-----默认绝对路径:取得路径相同------); File file2 new File(D:\\workspace\\test\\test1.txt); System.out.println(file2.getPath()); System.out.println(file2.getAbsolutePath()); System.out.println(file2.getCanonicalPath()); } catch (IOException e) { // TODOAuto-generated catch block e.printStackTrace(); } } } 程序执行结果如下 F:\eclipseworkspace\testejb -----默认相对路径取得路径不同------ ..\src\test1.txt F:\eclipseworkspace\testejb\..\src\test1.txt F:\eclipseworkspace\src\test1.txt -----默认相对路径取得路径不同------ .\test1.txt F:\eclipseworkspace\testejb\.\test1.txt F:\eclipseworkspace\testejb\test1.txt -----默认绝对路径:取得路径相同------ D:\workspace\test\test1.txt D:\workspace\test\test1.txt D:\workspace\test\test1.txt 结论 当输入为绝对路径时返回的都是绝对路径。 当输入为相对路径时 getPath()返回的是File构造方法里的路径是什么就是什么不增不减 getAbsolutePath()返回的其实是user.dirgetPath()的内容从上面F:\eclipseworkspace\testejb、F:\eclipseworkspace\testejb\..\src\test1.txt、F:\eclipseworkspace\testejb\.\test1.txt可以得出。 getCanonicalPath()返回的就是标准的将符号完全解析的路径