Here you can find the source of relativeFileToURI(File file)
Parameter | Description |
---|---|
file | the file to transform |
public static URI relativeFileToURI(File file)
//package com.java2s; /*/*w w w . j a v a 2 s.c o m*/ * Copyright (c) 2012 Data Harmonisation Panel * * All rights reserved. This program and the accompanying materials are made * available under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the License, * or (at your option) any later version. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution. If not, see <http://www.gnu.org/licenses/>. * * Contributors: * HUMBOLDT EU Integrated Project #030962 * Data Harmonisation Panel <http://www.dhpanel.eu> */ import java.io.File; import java.net.URI; public class Main { /** * Returns a URI for the given file. * * In contrast to {@link File#toURI()} it does not resolve a relative file, * but instead returns a relative URI. * * @param file the file to transform * @return a (relative) URI for the given file */ public static URI relativeFileToURI(File file) { if (file.isAbsolute()) return file.toURI(); else { String path = file.getPath(); if (File.separatorChar != '/') path = path.replace(File.separatorChar, '/'); return URI.create(path); } } }