Java Path File Name nio getFilePathName(Path filePath)

Here you can find the source of getFilePathName(Path filePath)

Description

get File Path Name

License

Open Source License

Declaration

public static String getFilePathName(Path filePath) 

Method Source Code

//package com.java2s;
/**/*  www  .j  av  a2  s .  c om*/
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library 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 Lesser General Public License for more
 * details.
 */

import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;

public class Main {
    public static String getFilePathName(Path filePath) {
        return fixFilePathName(filePath.toString());
    }

    public static String getFilePathName(String parentFilePathName, String fileName) {

        StringBuilder sb = new StringBuilder(3);

        sb.append(parentFilePathName);

        FileSystem fileSystem = FileSystems.getDefault();

        sb.append(fileSystem.getSeparator());

        sb.append(fileName);

        return fixFilePathName(sb.toString());
    }

    public static String fixFilePathName(String filePathName) {
        if (filePathName == null) {
            return "";
        }

        filePathName = filePathName.replace("\\", "/");

        if (filePathName.endsWith("/")) {
            filePathName = filePathName.substring(0, filePathName.length() - 1);
        }

        return filePathName;
    }
}

Related

  1. getFileNames(List fileNames, Path dir)
  2. getFileNames(List fileNames, Path dir, String ext, boolean recursive)
  3. getFileNames(List fileNames, Path dir, String sFilter)
  4. getFileNameWithoutExt(final Path file)
  5. getFilePath(String dirName)
  6. getFilePathsInFolder(String sensorName)
  7. getFilesFromDirectory(Path directory, List filenames)
  8. getFormattedDisplayName(String fileDisplayName, Path path, String baseDir)
  9. getFullFileName(Path path)