Here you can find the source of concatFileName(String fileName, Path pathLocation)
concatenates a given filename to the provided path in directory.
Parameter | Description |
---|---|
fileName | name of the file. |
pathLocation | location of the directory. |
public static String concatFileName(String fileName, Path pathLocation)
//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(); } }