码迷,mamicode.com
首页 > 其他好文 > 详细

相对绝对路径

时间:2020-03-15 16:23:17      阅读:60      评论:0      收藏:0      [点我收藏+]

标签:nbsp   ring   int   name   file   string   software   get   相对   

* 路径分隔符 ;
* 文件分隔符 \
* getPath():返回 【抽象路径名】--【字符串】
* getAbsolutePath():
* --【抽象路径名】是【绝对路径名】,getPath() 方法一样
* --【抽象路径名】是【空抽象路径名】, 返回【user.dir指定的路径】--字符串

package mypro04;
/**
 * 路径分隔符  ;
 * 文件分隔符  * getPath():返回 【抽象路径名】--【字符串】
 * getAbsolutePath():
 *     --【抽象路径名】是【绝对路径名】,getPath() 方法一样
 *     --【抽象路径名】是【空抽象路径名】, 返回【user.dir指定的路径】--字符串
 */

import java.io.File;

public class TestFIile {
    public static void main(String[] args) {
        //路径分隔符  ;
        System.out.println(File.pathSeparator);
        //文件分隔符 \
        System.out.println(File.separator);
        

        
        System.out.println("***********相对路径*******************");        
        //相对路径
        String parentpath="D:/learn/java/mycode"; //"D:/learn/java/mycode/"
        String name="Welcome.class";
        File file=new File(parentpath,name);
        
        
        System.out.println(file.getName());        //Welcome.class
        System.out.println(file.getPath());        //D:\learn\java\mycode\Welcome.class
        System.out.println(file.getParent());      //D:\learn\java\mycode        
        System.out.println(file.getAbsolutePath());//D:\learn\java\mycode\Welcome.class
        
        
        System.out.println("**********绝对路径********************");
        //绝对路径
        String absolutePath="D:/learn/java/mycode/Welcome.class";
        File file1=new File(absolutePath);
        System.out.println(file1.getName()); //         Welcome.class
        System.out.println(file1.getPath());//          D:\learn\java\mycode\Welcome.class
        System.out.println(file1.getParent());//         D:\learn\java\mycode
        System.out.println(file1.getAbsolutePath());//  D:\learn\java\mycode\Welcome.class
        
        System.out.println("**********没有盘符********************");
        //没有盘符 ;,以user.dir构建
        File file2=new File("Welcome.class");
        System.out.println(file2.getName()); //         Welcome.class
        System.out.println(file2.getPath());//          Welcome.class
        System.out.println(file2.getParent());//         null
        System.out.println(file2.getAbsolutePath());//  D:\software\eclipse\eclipse-workspace\mypro04\Welcome.class
                
    }


}

 

相对绝对路径

标签:nbsp   ring   int   name   file   string   software   get   相对   

原文地址:https://www.cnblogs.com/hapyygril/p/12498158.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!