Tabnine Logo
File.toURI
Code IndexAdd Tabnine to your IDE (free)

How to use
toURI
method
in
java.io.File

Best Java code snippets using java.io.File.toURI (Showing top 20 results out of 39,681)

Refine searchRefine arrow

  • URI.toURL
  • File.<init>
  • File.exists
  • URI.toString
  • List.add
  • URL.<init>
  • URLClassLoader.<init>
origin: google/guava

 /**
  * Returns the absolute uri of the Class-Path entry value as specified in <a
  * href="http://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Main_Attributes">JAR
  * File Specification</a>. Even though the specification only talks about relative urls,
  * absolute urls are actually supported too (for example, in Maven surefire plugin).
  */
 @VisibleForTesting
 static URL getClassPathEntry(File jarFile, String path) throws MalformedURLException {
  return new URL(jarFile.toURI().toURL(), path);
 }
}
origin: spring-projects/spring-framework

/**
 * This implementation returns a URL for the underlying file.
 * @see java.io.File#toURI()
 */
@Override
public URL getURL() throws IOException {
  return (this.file != null ? this.file.toURI().toURL() : this.filePath.toUri().toURL());
}
origin: stackoverflow.com

 String path = "/var/data/stuff/xyz.dat";
String base = "/var/data";
String relative = new File(base).toURI().relativize(new File(path).toURI()).getPath();
// relative == "stuff/xyz.dat"
origin: redisson/redisson

public URL find(String classname) {
  char sep = File.separatorChar;
  String filename = directory + sep
    + classname.replace('.', sep) + ".class";
  File f = new File(filename);
  if (f.exists())
    try {
      return f.getCanonicalFile().toURI().toURL();
    }
    catch (MalformedURLException e) {}
    catch (IOException e) {}
  return null;
}
origin: jenkinsci/jenkins

public void addPathFiles( Collection<File> paths )
  throws IOException
{
  for ( File f : paths )
  {
    urls.add( f.toURI().toURL() );
    addPathFile( f );
  }
}
origin: apache/flink

public static String createTempFileInDirectory(String dir, String contents) throws IOException {
  File f;
  do {
    f = new File(dir + "/" + randomFileName());
  } while (f.exists());
  f.getParentFile().mkdirs();
  f.createNewFile();
  f.deleteOnExit();
  try (BufferedWriter out = new BufferedWriter(new FileWriter(f))) {
    out.write(contents);
  }
  return f.toURI().toString();
}
origin: apache/flink

public static String constructTestURI(Class<?> forClass, String folder) {
  return new File(constructTestPath(forClass, folder)).toURI().toString();
}
origin: oblac/jodd

private static Collection<Arguments> testdata_testConvert_with_non_null_input() throws Exception{
  final List<Arguments> params = new ArrayList<>();
  params.add(Arguments.of(new URL("http://jodd.org/")));
  params.add(Arguments.of(new File(SystemUtil.info().getTempDir(), "jodd.txt")));
  params.add(Arguments.of(new File(SystemUtil.info().getTempDir(), "jodd.txt").toURI()));
  params.add(Arguments.of("http://jodd.org/"));
  return params;
}
origin: apache/incubator-druid

 @Test
 public void testExampleRegex() throws IOException
 {
  File tmpFile = new File(tmpDir, "renames-123.gz");
  tmpFile.createNewFile();
  Assert.assertTrue(tmpFile.exists());
  Assert.assertFalse(tmpFile.isDirectory());
  Assert.assertEquals(
    tmpFile.getAbsolutePath(),
    finder.getLatestVersion(tmpDir.toURI(), Pattern.compile("renames-[0-9]*\\.gz")).getPath()
  );
 }
}
origin: eclipse-vertx/vert.x

private static List<JavaFileObject> browseDir(String packageName, File directory) {
 List<JavaFileObject> result = new ArrayList<>();
 for (File childFile : directory.listFiles()) {
  if (childFile.isFile() && childFile.getName().endsWith(CLASS_FILE)) {
   String binaryName = packageName + "." + childFile.getName().replaceAll(CLASS_FILE + "$", "");
   result.add(new CustomJavaFileObject(childFile.toURI(), JavaFileObject.Kind.CLASS, binaryName));
  }
 }
 return result;
}
origin: redisson/redisson

JarClassPath(String pathname) throws NotFoundException {
  try {
    jarfile = new JarFile(pathname);
    jarfileURL = new File(pathname).getCanonicalFile()
                    .toURI().toURL().toString();
    return;
  }
  catch (IOException e) {}
  throw new NotFoundException(pathname);
}
origin: jenkinsci/jenkins

private @CheckForNull VersionNumber getPluginVersion(@Nonnull File pluginFile) {
  if (!pluginFile.exists()) {
    return null;
  }
  try {
    return getPluginVersion(pluginFile.toURI().toURL());
  } catch (MalformedURLException e) {
    return null;
  }
}
origin: apache/flink

public String createTempFile(String fileName, String contents) throws IOException {
  File f = createAndRegisterTempFile(fileName);
  if (!f.getParentFile().exists()) {
    f.getParentFile().mkdirs();
  }
  f.createNewFile();
  FileUtils.writeFileUtf8(f, contents);
  return f.toURI().toString();
}
origin: apache/incubator-druid

@Test
public void testSimpleOneFileLatestVersion() throws IOException
{
 File oldFile = File.createTempFile("old", ".txt", tmpDir);
 Assert.assertTrue(oldFile.exists());
 Assert.assertEquals(
   oldFile.getAbsolutePath(),
   finder.getLatestVersion(oldFile.toURI(), Pattern.compile(".*\\.txt")).getPath()
 );
}
origin: apache/incubator-druid

@Override
public String getPathForHadoop()
{
 return config.getStorageDirectory().getAbsoluteFile().toURI().toString();
}
origin: apache/flink

private static URLClassLoader createClassLoader(File root) throws MalformedURLException {
  return new URLClassLoader(
    new URL[]{root.toURI().toURL()},
    Thread.currentThread().getContextClassLoader());
}
origin: eclipse-vertx/vert.x

/**
 * Creates a classloader respecting the classpath option.
 *
 * @return the classloader.
 */
protected synchronized ClassLoader createClassloader() {
 URL[] urls = classpath.stream().map(path -> {
  File file = new File(path);
  try {
   return file.toURI().toURL();
  } catch (MalformedURLException e) {
   throw new IllegalStateException(e);
  }
 }).toArray(URL[]::new);
 return new URLClassLoader(urls, this.getClass().getClassLoader());
}
origin: pmd/pmd

private static URL[] fileToURL(List<File> files) throws IOException {
  List<URL> urlList = new ArrayList<>();
  for (File f : files) {
    urlList.add(f.toURI().toURL());
  }
  return urlList.toArray(new URL[0]);
}
origin: apache/flink

public static String createTempFileInDirectory(String dir, long bytes) throws IOException {
  File f;
  do {
    f = new File(dir + "/" + randomFileName());
  } while (f.exists());
  f.getParentFile().mkdirs();
  f.createNewFile();
  f.deleteOnExit();
  try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f))) {
    for (; bytes > 0; bytes--) {
      out.write(0);
    }
  }
  return f.toURI().toString();
}
origin: checkstyle/checkstyle

/**
 * Returns URI-representation of the path for the given file name.
 * The path is formed base on the root location.
 * This implementation uses 'src/test/resources/com/puppycrawl/tools/checkstyle/'
 * as a root location.
 * @param filename file name.
 * @return URI-representation of the path for the file with the given file name.
 */
protected final String getUriString(String filename) {
  return new File("src/test/resources/" + getPackageLocation() + "/" + filename).toURI()
      .toString();
}
java.ioFiletoURI

Javadoc

Returns a Uniform Resource Identifier for this file. The URI is system dependent and may not be transferable between different operating / file systems.

Popular methods of File

  • <init>
    Creates a new File instance by converting the givenfile: URI into an abstract pathname. The exact fo
  • exists
    Tests whether the file or directory denoted by this abstract pathname exists.
  • getAbsolutePath
    Returns the absolute pathname string of this abstract pathname. If this abstract pathname is already
  • getName
    Returns the name of the file or directory denoted by this abstract pathname. This is just the last n
  • isDirectory
  • mkdirs
  • delete
    Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a director
  • listFiles
    Returns an array of abstract pathnames denoting the files and directories in the directory denoted b
  • getParentFile
    Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not
  • getPath
    Converts this abstract pathname into a pathname string. The resulting string uses the #separator to
  • isFile
  • length
    Returns the length of the file denoted by this abstract pathname. The return value is unspecified if
  • isFile,
  • length,
  • createTempFile,
  • createNewFile,
  • toPath,
  • mkdir,
  • lastModified,
  • toString,
  • getCanonicalPath

Popular in Java

  • Running tasks concurrently on multiple threads
  • findViewById (Activity)
  • setRequestProperty (URLConnection)
  • getSharedPreferences (Context)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • JLabel (javax.swing)
  • JOptionPane (javax.swing)
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now