Java Path File Name nio concatFileName(String fileName, Path pathLocation)

Here you can find the source of concatFileName(String fileName, Path pathLocation)

Description

concatenates a given filename to the provided path in directory.

License

Open Source License

Parameter

Parameter Description
fileName name of the file.
pathLocation location of the directory.

Return

the path with directoryName + file.

Declaration

public static String concatFileName(String fileName, Path pathLocation) 

Method Source Code

//package com.java2s;
/*/*from   w  w w .  j  a  v  a2s .  c  om*/
 * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.nio.file.Path;

public class Main {
    /**
     * <p>
     * concatenates a given filename to the provided path in directory.
     * </p>
     * <p>
     * <b>Note : </b> this function is relevant since in Unix the directory would be separated from backslash and
     * in unix the folder will be separated from forward slash.
     * </p>
     *
     * @param fileName     name of the file.
     * @param pathLocation location of the directory.
     * @return the path with directoryName + file.
     */
    public static String concatFileName(String fileName, Path pathLocation) {
        final String windowsFolderSeparator = "\\";
        final String unixFolderSeparator = "/";
        StringBuilder path = new StringBuilder(pathLocation.toAbsolutePath().toString());
        if (pathLocation.endsWith(windowsFolderSeparator)) {
            path = path.append(windowsFolderSeparator).append(fileName);
        } else {
            path = path.append(unixFolderSeparator).append(fileName);
        }
        return path.toString();
    }
}

Related

  1. addPath(JarOutputStream outputStream, Path path, String entryName)
  2. addRestorePermissions(String username, Path file)
  3. appendTargetToBuildFile(String targetName, Path dir)
  4. checkFile(final String friendlyname, final Path file, final boolean isdirectory, final boolean canwrite)
  5. compileAndLoad(Path basePath, String className)
  6. convertFilePathToName(Path file)
  7. detectFilePath(String propertyName, String confFileName)
  8. endsWith(File file, String pathname)
  9. fileName(final Path path)