Here you can find the source of toUri(File folder)
Parameter | Description |
---|---|
folderpath | platform specific path as <pre>UNIX: /tmp/imports/</pre> or <pre>MS Win: c:\imports</pre> or <pre>UNC MS Win: \\laptop\My Documents\</pre> are valid options |
static URI toUri(File folder)
//package com.java2s; /*//from w ww . j a v a2 s. co m * Copyright (C) 2011 Jan Pokorsky * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.net.URI; public class Main { /** * Translates platform specific path to independent form as URI * * @param folderpath platform specific path as <pre>UNIX: /tmp/imports/</pre> * or <pre>MS Win: c:\imports</pre> or <pre>UNC MS Win: \\laptop\My Documents\</pre> * are valid options * @return an abstract path */ static URI toUri(File folder) { if (folder.exists() && !folder.isDirectory()) { throw new IllegalArgumentException("Invalid folder path: '" + folder + '\''); } // File.toURI always terminates folder path with slash but the folder must exists return folder.toURI().normalize(); } }