/** * Get the file path object for the given path. * Windows-style '\' is replaced with '/'. * * @param path the path * @return the file path object */ public static FilePath get(String path) { path = path.replace('\\', '/'); int index = path.indexOf(':'); registerDefaultProviders(); if (index < 2) { // use the default provider if no prefix or // only a single character (drive name) return defaultProvider.getPath(path); } String scheme = path.substring(0, index); FilePath p = providers.get(scheme); if (p == null) { // provider not found - use the default p = defaultProvider; } return p.getPath(path); }
/** * Create a new temporary file. * * @param suffix the suffix * @param deleteOnExit if the file should be deleted when the virtual * machine exists * @param inTempDir if the file should be stored in the temporary directory * @return the name of the created file */ public FilePath createTempFile(String suffix, boolean deleteOnExit, boolean inTempDir) throws IOException { while (true) { FilePath p = getPath(name + getNextTempFileNamePart(false) + suffix); if (p.exists() || !p.createFile()) { // in theory, the random number could collide getNextTempFileNamePart(true); continue; } p.open("rw").close(); return p; } }