Here you can find the source of getAbsolutePath(String fileName)
fileName
Parameter | Description |
---|---|
fileName | the name of a file |
public static String getAbsolutePath(String fileName)
//package com.java2s; /*/*from ww w .ja v a 2 s . co m*/ * Copyright 2016 Red Hat, Inc. * * Red Hat 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.net.URISyntaxException; import java.net.URL; import java.nio.file.Paths; public class Main { /** * Returns the absolute path to a file with name <code>fileName</code> * @param fileName the name of a file * @return absolute path to the file */ public static String getAbsolutePath(String fileName) { return Paths.get(fileName).toAbsolutePath().toString(); } /** * Returns the absolute path to a resource addressed by the given <code>url</code> * @param resource URL * @return absolute path to the resource */ public static String getAbsolutePath(URL url) { try { return url != null ? Paths.get(url.toURI()).toAbsolutePath().toString() : null; } catch (URISyntaxException e) { throw new RuntimeException(e); } } }