Java File to URL fileToURL(File file)

Here you can find the source of fileToURL(File file)

Description

file To URL

License

Open Source License

Declaration

public static URL fileToURL(File file) throws IOException 

Method Source Code


//package com.java2s;
/*/* w  ww.  java  2s .  co m*/
 * This file is part of the Jose Project
 * see http://jose-chess.sourceforge.net/
 * (c) 2002-2006 Peter Sch?fer
 *
 * 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 2 of the License, or
 * (at your option) any later version.
 *
 */

import java.io.File;

import java.io.IOException;

import java.net.URL;

public class Main {
    public static URL fileToURL(File file) throws IOException {
        file = file.getCanonicalFile();
        String s = file.getAbsolutePath();
        s = s.replace('\\', '/');
        if (!s.startsWith("/"))
            s = "/" + s;
        if (!s.endsWith("/") && file.isDirectory())
            s = s + "/";
        return new URL("file", "", s);
    }
}

Related

  1. fileToURL(File file)
  2. fileToURL(File file)
  3. fileToUrl(File file)
  4. FileToURL(File file)
  5. fileToURL(File file)
  6. fileToURL(File file)
  7. fileToURL(File file)
  8. fileToURL(File file)
  9. fileToURL(File file)