集册 Java实例教程 获取建立给定文件的规范路径的各个路径元素。

获取建立给定文件的规范路径的各个路径元素。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

489
获取构建给定文件的规范路径的各个路径元素。

// Copyright (C) 2001-2012 Michael Bayne, et al./* from n o w j a v a . c o m - 时代Java*/

//package com.nowjava;

import java.io.File;

import java.io.IOException;


public class Main {

    /**

     * Gets the individual path elements building up the canonical path to the given file.

     */

    public static String[] getCanonicalPathElements(File file)

            throws IOException {

        file = file.getCanonicalFile();


        // If we were a file, get its parent

        if (!file.isDirectory()) {

            file =
展开阅读全文