Java URI to Relative URI getRelativeLocalURI(String suffix)

Here you can find the source of getRelativeLocalURI(String suffix)

Description

Now works for both linux and windows

License

Open Source License

Parameter

Parameter Description
suffix a parameter

Declaration

public static URI getRelativeLocalURI(String suffix) 

Method Source Code

//package com.java2s;
/* /*from   w w w.ja  va2  s. c  om*/
 *  Copyright (C) 2008 Thomas Klapiscak (t.g.klapiscak@durham.ac.uk)
 *  
 *  This file is part of JASDL.
 *
 *  JASDL is free software: you can redistribute it and/or modify
 *  it under the terms of the Lesser GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  JASDL 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
 *  Lesser GNU General Public License for more details.
 *
 *  You should have received a copy of the Lesser GNU General Public License
 *  along with JASDL.  If not, see <http://www.gnu.org/licenses/>.
 *  
 */

import java.io.File;
import java.net.URI;

public class Main {
    /**
     * Now works for both linux and windows
     * @param suffix
     * @return
     */
    public static URI getRelativeLocalURI(String suffix) {
        return URI.create("file:///" + getCurrentDir().replace("\\", "/")
                + suffix);
    }

    public static String getCurrentDir() {
        File dir1 = new File(".");
        String strCurrentDir = "";
        try {
            strCurrentDir = dir1.getCanonicalPath();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return strCurrentDir;
    }
}

Related

  1. getRedirectUri(URI uri, String location)
  2. getRelativeName(File file, URI directory)
  3. getRelativePath(URI base, File file)
  4. getRelativePath(URI targetURI, URI baseURI)
  5. getRelativePath(URI targetUri, URI baseUri)