Java Path Format formatPath(String path)

Here you can find the source of formatPath(String path)

Description

Formats a path for display to the user.

License

Open Source License

Parameter

Parameter Description
path in a format used by the plugin

Return

user friendly path

Declaration

public static String formatPath(String path) 

Method Source Code

//package com.java2s;
/*/*from  w  ww.ja v  a 2s.  c o m*/
 * Jopr Management Platform
 * Copyright (C) 2005-2008 Red Hat, Inc.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2, as
 * published by the Free Software Foundation, and/or the GNU Lesser
 * General Public License, version 2.1, also as published by the Free
 * Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License and the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * and the GNU Lesser General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

import java.io.File;
import java.io.IOException;

public class Main {
    /**
     * Formats a path for display to the user.
     *
     * @param  path in a format used by the plugin
     *
     * @return user friendly path
     */
    public static String formatPath(String path) {
        String formattedPath;
        if (path == null) {
            formattedPath = "";
        } else {
            File file = new File(path);

            if (!file.isAbsolute()) {
                formattedPath = file.getPath();
            } else {
                try {
                    formattedPath = file.getCanonicalPath();
                } catch (IOException e) {
                    // incase something goes wrong getting the canonical path, just use the absolute
                    formattedPath = file.getAbsolutePath();
                }
            }
        }

        return formattedPath;
    }
}

Related

  1. formatPath(String inputPath)
  2. formatPath(String path)