/** * Get the file or directory name (the last element of the path). * This method is similar to Java 7 <code>java.nio.file.Path.getName</code>. * * @param path the directory and file name * @return just the file name */ public static String getName(String path) { return FilePath.get(path).getName(); }
/** * Rename a file if this is allowed. This method is similar to Java 7 * <code>java.nio.file.Files.move</code>. * * @param source the old fully qualified file name * @param target the new fully qualified file name */ public static void move(String source, String target) { FilePath.get(source).moveTo(FilePath.get(target), false); }
/** * Get the parent directory of a file or directory. This method returns null * if there is no parent. This method is similar to Java 7 * <code>java.nio.file.Path.getParent</code>. * * @param fileName the file or directory name * @return the parent directory name */ public static String getParent(String fileName) { FilePath p = FilePath.get(fileName).getParent(); return p == null ? null : p.toString(); }
/** * Rename a file if this is allowed, and try to atomically replace an * existing file. This method is similar to Java 7 * <code>java.nio.file.Files.move</code>. * * @param source the old fully qualified file name * @param target the new fully qualified file name */ public static void moveAtomicReplace(String source, String target) { FilePath.get(source).moveTo(FilePath.get(target), true); }
/** * Checks if a file exists. * This method is similar to Java 7 <code>java.nio.file.Path.exists</code>. * * @param fileName the file name * @return true if it exists */ public static boolean exists(String fileName) { return FilePath.get(fileName).exists(); }
/** * Check if the file name includes a path. This method is similar to Java 7 * <code>java.nio.file.Path.isAbsolute</code>. * * @param fileName the file name * @return if the file name is absolute */ public static boolean isAbsolute(String fileName) { return FilePath.get(fileName).isAbsolute(); }
/** * Get the last modified date of a file. * This method is similar to Java 7 * <code>java.nio.file.attribute.Attributes. * readBasicFileAttributes(file).lastModified().toMillis()</code> * * @param fileName the file name * @return the last modified date */ public static long lastModified(String fileName) { return FilePath.get(fileName).lastModified(); }
/** * Check if it is a file or a directory. * <code>java.nio.file.attribute.Attributes. * readBasicFileAttributes(file).isDirectory()</code> * * @param fileName the file or directory name * @return true if it is a directory */ public static boolean isDirectory(String fileName) { return FilePath.get(fileName).isDirectory(); }
/** * Check if the file is writable. * This method is similar to Java 7 * <code>java.nio.file.Path.checkAccess(AccessMode.WRITE)</code> * * @param fileName the file name * @return if the file is writable */ public static boolean canWrite(String fileName) { return FilePath.get(fileName).canWrite(); }
/** * Create a directory (all required parent directories must already exist). * This method is similar to Java 7 * <code>java.nio.file.Path.createDirectory</code>. * * @param directoryName the directory name */ public static void createDirectory(String directoryName) { FilePath.get(directoryName).createDirectory(); }
/** * Delete a file or directory if it exists. * Directories may only be deleted if they are empty. * This method is similar to Java 7 * <code>java.nio.file.Path.deleteIfExists</code>. * * @param path the file or directory name */ public static void delete(String path) { FilePath.get(path).delete(); }
/** * 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); }
/** * Disable the ability to write. The file can still be deleted afterwards. * * @param fileName the file name * @return true if the call was successful */ public static boolean setReadOnly(String fileName) { return FilePath.get(fileName).setReadOnly(); }
/** * Get the file name of a part file. * * @param id the part id * @return the file name including the part id */ FilePath getBase(int id) { return FilePath.get(getName(id)); }
/** * Get the base path for the given wrapped path. * * @param path the path including the scheme prefix * @return the base file path */ protected FilePath unwrap(String path) { return FilePath.get(path.substring(getScheme().length() + 1)); }
/** * Create a new file. This method is similar to Java 7 * <code>java.nio.file.Path.createFile</code>, but returns false instead of * throwing a exception if the file already existed. * * @param fileName the file name * @return true if creating was successful */ public static boolean createFile(String fileName) { return FilePath.get(fileName).createFile(); }
/** * Get the size of a file in bytes * This method is similar to Java 7 * <code>java.nio.file.attribute.Attributes. * readBasicFileAttributes(file).size()</code> * * @param fileName the file name * @return the size in bytes */ public static long size(String fileName) { return FilePath.get(fileName).size(); }
/** * Create an input stream to read from the file. * This method is similar to Java 7 * <code>java.nio.file.Path.newInputStream</code>. * * @param fileName the file name * @return the input stream */ public static InputStream newInputStream(String fileName) throws IOException { return FilePath.get(fileName).newInputStream(); }
/** * Get the canonical file or directory name. This method is similar to Java * 7 <code>java.nio.file.Path.toRealPath</code>. * * @param fileName the file name * @return the normalized file name */ public static String toRealPath(String fileName) { return FilePath.get(fileName).toRealPath().toString(); }
@Override public boolean isAbsolute() { String fileName = translateFileName(name); return FilePath.get(fileName).isAbsolute(); }