Class FileUtils

java.lang.Object
net.thevpc.common.io.FileUtils

public class FileUtils extends Object
Author:
taha.bensalah@gmail.com
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • deleteFolderTree

      public static boolean deleteFolderTree(File folder, FileFilter fileFilter)
    • findFilePathsOrError

      public static String[] findFilePathsOrError(String path, File cwd, FileFilter fileFilter)
    • findFilesOrError

      public static File[] findFilesOrError(String path, File cwd, FileFilter fileFilter)
    • findFiles

      public static File[] findFiles(String path, File cwd, FileFilter fileFilter)
    • findFiles

      public static File[] findFiles(String path, String base, File cwd, FileFilter fileFilter)
    • getCanonicalPath

      public static String getCanonicalPath(File fileName)
    • probeContentType

      public static String probeContentType(String fileName)
    • probeContentType

      public static String probeContentType(File file)
    • probeContentType

      public static String probeContentType(URL url)
    • toFileLenient

      public static File toFileLenient(String path)
    • expandFile

      public static File expandFile(String path)
    • expandPath

      public static String expandPath(String path)
      path expansion replaces ~ with ${user.home} property value
      Parameters:
      path - to expand
      Returns:
      expanded path
    • replaceInFile

      public static void replaceInFile(File file, String oldContent, String newContent) throws IOException
      Throws:
      IOException
    • replaceAllInFile

      public static void replaceAllInFile(File file, String oldContent, String newContent) throws IOException
      Throws:
      IOException
    • replaceInFolder

      public static void replaceInFolder(File folder, FileFilter fileFilter, boolean recurse, String oldContent, String newContent) throws IOException
      Throws:
      IOException
    • getFileBaseName

      public static String getFileBaseName(File f)
      retourne le nom du fichier (sans l'extension)
      Parameters:
      f - fichier
      Returns:
      file name
    • getFileBaseName

      public static String getFileBaseName(String name)
    • getFileParentPath

      public static String getFileParentPath(String name)
    • getFileName

      public static String getFileName(String name)
    • getFilePath

      public static String getFilePath(File file)
      try to return CanonicalPath otherwise AbsolutePath
      Parameters:
      file - file
      Returns:
      CanonicalPath or AbsolutePath (if IOException)
    • canonize

      public static File canonize(File file)
    • getNameWithExtension

      public static String getNameWithExtension(String name, String extension)
    • getFileNameWithoutExtension

      public static String getFileNameWithoutExtension(File f)
      retourne le nom du fichier (sans l'extension)
      Parameters:
      f - fichier
      Returns:
      file name
    • getFileNameWithoutExtension

      public static String getFileNameWithoutExtension(String name)
    • getNameExtension

      public static String getNameExtension(String name)
    • isFolderWritable

      public static boolean isFolderWritable(File folder)
    • mkdirs

      public static void mkdirs(File root, String... relativePaths) throws IOException
      Throws:
      IOException
    • createTempFile

      public static File createTempFile(URL url) throws IOException
      Throws:
      IOException
    • getFileExtension

      public static String getFileExtension(File f)
    • getFileExtension

      public static String getFileExtension(String s)
      file extension
      Parameters:
      s - file name
      Returns:
      file extension
    • isFilePath

      public static boolean isFilePath(String path)
    • getAbsolutePath

      public static String getAbsolutePath(File cwd, String path)
    • getAbsoluteFile

      public static File getAbsoluteFile(File cwd, String path)
    • getAbsoluteFile

      public static File getAbsoluteFile(File cwd, File path)
    • expandPath

      public static String[] expandPath(String path, File cwd)
    • getAbsolutePath

      public static String getAbsolutePath(String path)
    • getAbsoluteFile

      public static File getAbsoluteFile(File path)
    • isAbsolutePath

      public static boolean isAbsolutePath(String location)
    • getNativePath

      public static String getNativePath(String path)
    • getRelativePath

      public static String getRelativePath(File parent, File son)
      relative path
      Parameters:
      parent - parent
      son - son
      Returns:
      relative path
    • createParents

      public static void createParents(File f)
    • createExtensionFilter

      public static FileFilter createExtensionFilter(FileUtils.ExtentionFilterOptions o, String... extensions) throws IOException
      Throws:
      IOException
    • copyTree

      public static void copyTree(File in, File out) throws IOException
      Throws:
      IOException
    • copyTree

      public static void copyTree(File in, File out, FileFilter filter) throws IOException
      Throws:
      IOException
    • changeFileSuffix

      public static File changeFileSuffix(File file, String suffix)
    • changeFileExtension

      public static File changeFileExtension(File file, String suffix)
    • toValidFileName

      public static String toValidFileName(String name, String defaultName)
    • getAbsoluteFile2

      public static String getAbsoluteFile2(String path, String cwd)
      should promote this to FileUtils !!
      Parameters:
      path - path
      cwd - current work dir
      Returns:
      absolute path