List of usage examples for java.io File toURI
public URI toURI()
From source file:FileMonitor.java
/** * Utility to convert {@link File} to {@link URL}. * /*w ww. j av a2 s . c o m*/ * @param filePath the path of the file * @return the {@link URL} representation of the file. * @throws MalformedURLException * @throws IllegalArgumentException if the file path is null, empty or blank */ public static URL convertFileToURL(String filePath) throws MalformedURLException { File file = new File(filePath.trim()); return file.toURI().toURL(); }
From source file:net.grinder.util.UrlUtil.java
/** * Convert the given file to string formated URL. * /*from ww w . ja va2 s . c o m*/ * @param file * file * @return URL */ public static URL toURL(File file) { try { return file.toURI().toURL(); } catch (MalformedURLException e) { return null; } }
From source file:Main.java
private static void addToClassPath(String path) throws IOException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { File file = new File(path); if (file.exists()) { addtoClassLoader(file.toURI().toURL()); } else {// w ww . ja v a2s .com throw new IOException("File Not Found"); } }
From source file:com.clustercontrol.plugin.ClassUtils.java
/** * ???CLASSPATH??<br/>/*ww w . ja va 2 s . c o m*/ * @param directory ? * @throws IOException */ public static void addDirToClasspath(File directory) throws IOException { if (directory.exists()) { File[] files = directory.listFiles(); if (files != null) { for (File file : files) { addURL(file.toURI().toURL()); } } } }
From source file:Main.java
/** * @param filename/*from w ww. ja v a 2 s .c om*/ * @return the url */ public static String fileToURL(String filename) { File f = new File(filename); try { return f.toURI().toURL().toString(); } catch (MalformedURLException e) { return filename; } }
From source file:com.sun.star.lib.loader.FileFind.java
/** * Looks for files recursively in a directory tree * @param inFolder//w w w .j a v a 2 s .co m * @param findTheseFiles * @return */ public static URL[] findFiles(String inFolder, String[] findTheseFiles) { List<URL> urls = new ArrayList<URL>(0); Collection<File> files = FileUtils.listFiles(new File(inFolder), new NameFileFilter(findTheseFiles), TrueFileFilter.INSTANCE); for (File file : files) { try { urls.add(file.toURI().toURL()); } catch (MalformedURLException ex) { log.error("error while locating jar", ex); } } return urls.toArray(new URL[urls.size()]); }
From source file:es.molabs.io.utils.FileHelper.java
public static URL[] getFiles(URL path, boolean recursive, String... extensions) throws IOException { URL[] urls = null;// w w w . j av a2 s. com try { Collection<File> fileCollection = FileUtils.listFiles(new File(path.toURI()), extensions, recursive); urls = new URL[fileCollection.size()]; Iterator<File> iterator = fileCollection.iterator(); int index = 0; while (iterator.hasNext()) { File file = iterator.next(); urls[index++] = file.toURI().toURL(); } } catch (URISyntaxException USe) { throw new IOException(USe); } return urls; }
From source file:net.orfjackal.dimdwarf.server.ApplicationLoader.java
private static URL asUrl(File file) { try {/*from w ww . j ava 2 s . com*/ return file.toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:Main.java
private static void zipDir(String dir, ZipOutputStream out) throws IOException { File directory = new File(dir); URI base = directory.toURI(); ArrayList<File> filesToZip = new ArrayList<File>(); GetFiles(directory, filesToZip);//from www . j a v a 2 s. c o m for (int i = 0; i < filesToZip.size(); ++i) { FileInputStream in = new FileInputStream(filesToZip.get(i)); String name = base.relativize(filesToZip.get(i).toURI()).getPath(); out.putNextEntry(new ZipEntry(name)); byte[] buf = new byte[4096]; int bytes = 0; while ((bytes = in.read(buf)) != -1) { out.write(buf, 0, bytes); } out.closeEntry(); in.close(); } out.finish(); out.flush(); }
From source file:com.github.mbredel.commons.configuration.ConfigurationAssert.java
/** * Helper method for converting a file to a URL. * * @param file the file//from w ww .ja v a 2 s .c o m * @return the corresponding URL * @throws ConfigurationRuntimeException if the URL cannot be constructed */ private static URL urlFromFile(File file) { try { return file.toURI().toURL(); } catch (MalformedURLException mex) { throw new ConfigurationRuntimeException(mex); } }