Package jmri.util

Class FileUtil


  • public final class FileUtil
    extends java.lang.Object
    Common utility methods for working with Files.

    All methods in this class call the identical method from the default instance of FileUtilSupport.

    See Also:
    FileUtilSupport
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String HOME
      Portable reference to the user's home directory.
      static java.lang.String PREFERENCES
      Portable reference to the JMRI user's files and preferences directory.
      static java.lang.String PROFILE
      Portable reference to the current profile directory.
      static java.lang.String PROGRAM
      Portable reference to items in the JMRI program directory.
      static java.lang.String SCRIPTS
      Portable reference to the current scripts directory.
      static char SEPARATOR
      The portable file path component separator.
      static java.lang.String SETTINGS
      Portable reference to the JMRI applications preferences directory.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void appendTextToFile​(java.io.File file, java.lang.String text)
      Simple helper method to just append a text string to the end of the given filename.
      static void backup​(java.io.File file)
      Backup a file.
      static void copy​(java.io.File source, java.io.File dest)
      Copy a file or directory.
      static void createDirectory​(java.io.File dir)
      Create a directory if required.
      static void createDirectory​(java.lang.String path)
      Create a directory if required.
      static boolean delete​(java.io.File path)
      Recursively delete a path.
      static java.net.URL fileToURL​(java.io.File file)
      Return the URL for a given File.
      static java.net.URI findExternalFilename​(java.lang.String path)
      Get the URL of a portable filename if it can be located using findURL(java.lang.String)
      static java.util.Set<java.io.File> findFiles​(java.lang.String name, java.lang.String root)
      Find all files matching the given name under the given root directory within both the user and installed file locations.
      static java.util.Set<java.io.File> findFiles​(java.lang.String name, java.lang.String root, FileUtil.Location location)
      Find all files matching the given name under the given root directory within the specified location.
      static java.io.InputStream findInputStream​(java.lang.String path)
      Search for a file or JAR resource by name and return the InputStream for that file.
      static java.io.InputStream findInputStream​(java.lang.String path, java.lang.String... searchPaths)
      Search for a file or JAR resource by name and return the InputStream for that file.
      static java.io.InputStream findInputStream​(java.lang.String path, FileUtil.Location locations)
      Search for a file or JAR resource by name and return the InputStream for that file.
      static java.io.InputStream findInputStream​(java.lang.String path, FileUtil.Location locations, java.lang.String... searchPaths)
      Search for a file or JAR resource by name and return the InputStream for that file.
      static java.net.URI findURI​(java.lang.String path)
      Search for a file or JAR resource by name and return the URI for that file.
      static java.net.URI findURI​(java.lang.String path, java.lang.String... searchPaths)
      Search for a file or JAR resource by name and return the URI for that file.
      static java.net.URI findURI​(java.lang.String path, FileUtil.Location locations)
      Search for a file or JAR resource by name and return the URI for that file.
      static java.net.URI findURI​(java.lang.String path, FileUtil.Location locations, java.lang.String... searchPaths)
      Search for a file or JAR resource by name and return the URI for that file.
      static java.net.URL findURL​(java.lang.String path)
      Search for a file or JAR resource by name and return the URL for that file.
      static java.net.URL findURL​(java.lang.String path, java.lang.String... searchPaths)
      Search for a file or JAR resource by name and return the URL for that file.
      static java.net.URL findURL​(java.lang.String path, FileUtil.Location locations)
      Search for a file or JAR resource by name and return the URL for that file.
      static java.net.URL findURL​(java.lang.String path, FileUtil.Location locations, java.lang.String... searchPaths)
      Search for a file or JAR resource by name and return the URL for that file.
      static java.lang.String getAbsoluteFilename​(java.lang.String path)
      Convert a portable filename into an absolute filename, using ProfileManager.getActiveProfile() as the base.
      static java.lang.String getAbsoluteFilename​(Profile profile, java.lang.String path)
      Convert a portable filename into an absolute filename.
      static FileUtilSupport getDefault()
      Get the default instance of FileUtilSupport.
      static java.lang.String getExternalFilename​(java.lang.String pName)
      Get the resource file corresponding to a name.
      static java.lang.String getExternalFilename​(Profile profile, java.lang.String pName)
      Get the resource file corresponding to a name.
      static java.io.File getFile​(java.lang.String path)
      Get the File that path refers to.
      static java.io.File getFile​(Profile profile, java.lang.String path)
      Get the File that path refers to.
      static java.lang.String getHomePath()
      Get the user's home directory.
      static java.lang.String getPortableFilename​(java.io.File file)
      Convert a File object's path to our preferred storage form.
      static java.lang.String getPortableFilename​(java.io.File file, boolean ignoreUserFilesPath, boolean ignoreProfilePath)
      Convert a File object's path to our preferred storage form.
      static java.lang.String getPortableFilename​(java.lang.String filename)
      Convert a filename string to our preferred storage form.
      static java.lang.String getPortableFilename​(java.lang.String filename, boolean ignoreUserFilesPath, boolean ignoreProfilePath)
      Convert a filename string to our preferred storage form.
      static java.lang.String getPortableFilename​(Profile profile, java.io.File file)
      Convert a File object's path to our preferred storage form.
      static java.lang.String getPortableFilename​(Profile profile, java.io.File file, boolean ignoreUserFilesPath, boolean ignoreProfilePath)
      Convert a File object's path to our preferred storage form.
      static java.lang.String getPortableFilename​(Profile profile, java.lang.String filename)
      Convert a filename string to our preferred storage form.
      static java.lang.String getPortableFilename​(Profile profile, java.lang.String filename, boolean ignoreUserFilesPath, boolean ignoreProfilePath)
      Convert a filename string to our preferred storage form.
      static java.lang.String getPreferencesPath()
      Get the preferences directory.
      static java.lang.String getProfilePath()
      Get the profile directory.
      static java.lang.String getProfilePath​(Profile profile)
      Get the profile directory.
      static java.lang.String getProgramPath()
      Get the JMRI program directory.
      static java.lang.String getScriptsPath()
      Get the path to the scripts directory using the Profile returned by ProfileManager.getActiveProfile() as the base.
      static java.lang.String getScriptsPath​(Profile profile)
      Get the path to the scripts directory.
      static java.net.URI getURI​(java.lang.String path)
      Get the File that path refers to.
      static java.net.URL getURL​(java.lang.String path)
      Get the URL that path refers to.
      static java.net.URL getURL​(java.net.URI uri)
      Convenience method to get the URL from a URI.
      static java.lang.String getUserFilesPath()
      Get the user's files directory.
      static java.lang.String getUserFilesPath​(Profile profile)
      Get the user's files directory.
      static java.lang.String getUserResourcePath()
      Get the resources directory within the user's files directory.
      static boolean isPortableFilename​(java.lang.String filename)
      Test if the given filename is a portable filename.
      static java.util.jar.JarFile jmriJarFile()
      Get the JMRI distribution jar file.
      static void logFilePaths()
      Log all paths at the INFO level.
      static java.lang.String readFile​(java.io.File file)
      Read a text file into a String.
      static java.lang.String readURL​(java.net.URL url)
      Read a text URL into a String.
      static void rotate​(java.io.File file, int max, java.lang.String extension)
      Rotate a file and its backups, retaining only a set number of backups.
      static java.lang.String sanitizeFilename​(java.lang.String name)
      Replaces most non-alphanumeric characters in name with an underscore.
      static void setProgramPath​(java.io.File path)
      Set the JMRI program directory.
      static void setProgramPath​(java.lang.String path)
      Set the JMRI program directory.
      static void setScriptsPath​(Profile profile, java.lang.String path)
      Set the path to python scripts.
      static void setUserFilesPath​(Profile profile, java.lang.String path)
      Set the user's files directory.
      static java.net.URI urlToURI​(java.net.URL url)
      Return the URI for a given URL
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait