/** * Open a random access file object. * This method is similar to Java 7 * <code>java.nio.channels.FileChannel.open</code>. * * @param fileName the file name * @param mode the access mode. Supported are r, rw, rws, rwd * @return the file object */ public static FileChannel open(String fileName, String mode) throws IOException { return FilePath.get(fileName).open(mode); }
/** * 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; } }