JAVA IO - 文件絕對路徑

import java.io.File;


public class GetFilePath {
    public static void main(String args[]){
    	File file = new File("C:\\work\\hello\\helloworld.txt");
    	System.out.println("The file path is " + file.getAbsolutePath());
    	
    	String path = file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf(File.separator));
    	System.out.println("The abs path is " + path);
    }
}
相關文章
相關標籤/搜索