Class Files

java.lang.Object
com.landawn.abacus.guava.Files
Direct Known Subclasses:
Files.MoreFiles

public abstract class Files extends Object
Copied from Google Guava under Apache License v2. The purpose is to provide unified API.
  • Method Details

    • newReader

      public static BufferedReader newReader(File file, Charset charset) throws FileNotFoundException
      Parameters:
      file -
      charset -
      Returns:
      Throws:
      FileNotFoundException - the file not found exception
    • newWriter

      public static BufferedWriter newWriter(File file, Charset charset) throws FileNotFoundException
      Parameters:
      file -
      charset -
      Returns:
      Throws:
      FileNotFoundException - the file not found exception
    • asByteSource

      public static com.google.common.io.ByteSource asByteSource(File file)
      As byte source.
      Parameters:
      file -
      Returns:
    • asByteSource

      @SafeVarargs public static com.google.common.io.ByteSource asByteSource(Path path, OpenOption... options)
      As byte source.
      Parameters:
      path -
      options -
      Returns:
    • asByteSink

      @SafeVarargs public static com.google.common.io.ByteSink asByteSink(File file, com.google.common.io.FileWriteMode... modes)
      As byte sink.
      Parameters:
      file -
      modes -
      Returns:
    • asByteSink

      @SafeVarargs public static com.google.common.io.ByteSink asByteSink(Path path, OpenOption... options)
      As byte sink.
      Parameters:
      path -
      options -
      Returns:
    • asCharSource

      public static com.google.common.io.CharSource asCharSource(File file, Charset charset)
      As char source.
      Parameters:
      file -
      charset -
      Returns:
    • asCharSource

      @SafeVarargs public static com.google.common.io.CharSource asCharSource(Path path, Charset charset, OpenOption... options)
      As char source.
      Parameters:
      path -
      charset -
      options -
      Returns:
    • asCharSink

      @SafeVarargs public static com.google.common.io.CharSink asCharSink(File file, Charset charset, com.google.common.io.FileWriteMode... modes)
      As char sink.
      Parameters:
      file -
      charset -
      modes -
      Returns:
    • asCharSink

      @SafeVarargs public static com.google.common.io.CharSink asCharSink(Path path, Charset charset, OpenOption... options)
      As char sink.
      Parameters:
      path -
      charset -
      options -
      Returns:
    • toByteArray

      public static byte[] toByteArray(File file) throws IOException
      To byte array.
      Parameters:
      file -
      Returns:
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • write

      public static void write(byte[] from, File to) throws IOException
      Parameters:
      from -
      to -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • equal

      public static boolean equal(File file1, File file2) throws IOException
      Parameters:
      file1 -
      file2 -
      Returns:
      true, if successful
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • equal

      public static boolean equal(Path path1, Path path2) throws IOException
      Parameters:
      path1 -
      path2 -
      Returns:
      true, if successful
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • touch

      public static void touch(File file) throws IOException
      Parameters:
      file -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • touch

      public static void touch(Path path) throws IOException
      Parameters:
      path -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • createTempDir

      @Deprecated public static File createTempDir()
      Deprecated.
      For Android users, see the Data and File Storage overview to select an appropriate temporary directory (perhaps context.getCacheDir()). For developers on Java 7 or later, use Files.createTempDirectory(java.nio.file.Path, java.lang.String, java.nio.file.attribute.FileAttribute<?>...), transforming it to a File using toFile() if needed.
      Returns:
    • createParentDirs

      public static void createParentDirs(File file) throws IOException
      Creates the parent dirs.
      Parameters:
      file -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • createParentDirectories

      @SafeVarargs public static void createParentDirectories(Path path, FileAttribute<?>... attrs) throws IOException
      Creates the parent directories.
      Parameters:
      path -
      attrs -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • copy

      public static void copy(File from, OutputStream to) throws IOException
      Parameters:
      from -
      to -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • copy

      public static void copy(File from, File to) throws IOException
      Parameters:
      from -
      to -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • move

      public static void move(File from, File to) throws IOException
      Parameters:
      from -
      to -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • readLines

      public static List<String> readLines(File file, Charset charset) throws IOException
      Parameters:
      file -
      charset -
      Returns:
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • map

      public static MappedByteBuffer map(File file) throws IOException
      Parameters:
      file -
      Returns:
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • map

      public static MappedByteBuffer map(File file, FileChannel.MapMode mode) throws IOException
      Parameters:
      file -
      mode -
      Returns:
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • map

      public static MappedByteBuffer map(File file, FileChannel.MapMode mode, long size) throws IOException
      Parameters:
      file -
      mode -
      size -
      Returns:
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • simplifyPath

      public static String simplifyPath(String pathname)
      Parameters:
      pathname -
      Returns:
    • getNameWithoutExtension

      public static String getNameWithoutExtension(String file)
      Gets the name without extension.
      Parameters:
      file -
      Returns:
    • getNameWithoutExtension

      public static String getNameWithoutExtension(Path path)
      Gets the name without extension.
      Parameters:
      path -
      Returns:
    • getFileExtension

      public static String getFileExtension(String fullName)
      Gets the file extension.
      Parameters:
      fullName -
      Returns:
    • getFileExtension

      public static String getFileExtension(Path path)
      Gets the file extension.
      Parameters:
      path -
      Returns:
    • fileTraverser

      public static com.google.common.graph.Traverser<File> fileTraverser()
      Returns:
    • pathTraverser

      public static com.google.common.graph.Traverser<Path> pathTraverser()
      Returns:
    • listFiles

      public static ImmutableList<Path> listFiles(Path dir) throws IOException
      Parameters:
      dir -
      Returns:
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • deleteRecursively

      @SafeVarargs public static void deleteRecursively(Path path, com.google.common.io.RecursiveDeleteOption... options) throws IOException
      Parameters:
      path -
      options -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • deleteDirectoryContents

      @SafeVarargs public static void deleteDirectoryContents(Path path, com.google.common.io.RecursiveDeleteOption... options) throws IOException
      Delete directory contents.
      Parameters:
      path -
      options -
      Throws:
      IOException - Signals that an I/O exception has occurred.