ml.shifu.guagua.util
类 FileUtils

java.lang.Object
  继承者 ml.shifu.guagua.util.FileUtils

public final class FileUtils
extends Object

Copied from apache common-io source code.


字段摘要
static char SYSTEM_SEPARATOR
          The system separator character.
static char UNIX_SEPARATOR
          The Unix separator character.
static char WINDOWS_SEPARATOR
          The Windows separator character.
 
方法摘要
static void cleanDirectory(File directory)
          Cleans a directory without deleting it.
static void deleteDirectory(File directory)
          Deletes a directory recursively.
static boolean deleteQuietly(File file)
          Deletes a file, never throwing an exception.
static void forceDelete(File file)
          Deletes a file.
static void forceDeleteOnExit(File file)
          Schedules a file to be deleted when JVM exits.
static File getTempDirectory()
          Returns a File representing the system temporary directory.
static String getTempDirectoryPath()
          Returns the path to the system temporary directory.
static File getUserDirectory()
          Returns a File representing the user's home directory.
static String getUserDirectoryPath()
          Returns the path to the user's home directory.
static boolean isSymlink(File file)
          Determines whether the specified file is a Symbolic Link rather than an actual file.
static FileInputStream openInputStream(File file)
          Opens a FileInputStream for the specified file, providing better error messages than simply calling new FileInputStream(file).
static List<String> readLines(File file)
          Reads the contents of a file line by line to a List of Strings using the default encoding for the VM.
static List<String> readLines(File file, String encoding)
          Reads the contents of a file line by line to a List of Strings.
static List<String> readLines(InputStream input)
          Get the contents of an InputStream as a list of Strings, one entry per line, using the default character encoding of the platform.
static List<String> readLines(InputStream input, String encoding)
          Get the contents of an InputStream as a list of Strings, one entry per line, using the specified character encoding.
static List<String> readLines(Reader input)
          Get the contents of a Reader as a list of Strings, one entry per line.
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

UNIX_SEPARATOR

public static final char UNIX_SEPARATOR
The Unix separator character.

另请参见:
常量字段值

WINDOWS_SEPARATOR

public static final char WINDOWS_SEPARATOR
The Windows separator character.

另请参见:
常量字段值

SYSTEM_SEPARATOR

public static final char SYSTEM_SEPARATOR
The system separator character.

方法详细信息

getTempDirectoryPath

public static String getTempDirectoryPath()
Returns the path to the system temporary directory.

返回:
the path to the system temporary directory.
从以下版本开始:
Commons IO 2.0

getTempDirectory

public static File getTempDirectory()
Returns a File representing the system temporary directory.

返回:
the system temporary directory.
从以下版本开始:
Commons IO 2.0

getUserDirectoryPath

public static String getUserDirectoryPath()
Returns the path to the user's home directory.

返回:
the path to the user's home directory.
从以下版本开始:
Commons IO 2.0

getUserDirectory

public static File getUserDirectory()
Returns a File representing the user's home directory.

返回:
the user's home directory.
从以下版本开始:
Commons IO 2.0

deleteDirectory

public static void deleteDirectory(File directory)
                            throws IOException
Deletes a directory recursively.

参数:
directory - directory to delete
抛出:
IOException - in case deletion is unsuccessful

deleteQuietly

public static boolean deleteQuietly(File file)
Deletes a file, never throwing an exception. If file is a directory, delete it and all sub-directories.

The difference between File.delete() and this method are:

参数:
file - file or directory to delete, can be null
返回:
true if the file or directory was deleted, otherwise false
从以下版本开始:
Commons IO 1.4

cleanDirectory

public static void cleanDirectory(File directory)
                           throws IOException
Cleans a directory without deleting it.

参数:
directory - directory to clean
抛出:
IOException - in case cleaning is unsuccessful

forceDelete

public static void forceDelete(File file)
                        throws IOException
Deletes a file. If file is a directory, delete it and all sub-directories.

The difference between File.delete() and this method are:

参数:
file - file or directory to delete, must not be null
抛出:
NullPointerException - if the directory is null
FileNotFoundException - if the file was not found
IOException - in case deletion is unsuccessful

forceDeleteOnExit

public static void forceDeleteOnExit(File file)
                              throws IOException
Schedules a file to be deleted when JVM exits. If file is directory delete it and all sub-directories.

参数:
file - file or directory to delete, must not be null
抛出:
NullPointerException - if the file is null
IOException - in case deletion is unsuccessful

isSymlink

public static boolean isSymlink(File file)
                         throws IOException
Determines whether the specified file is a Symbolic Link rather than an actual file.

Will not return true if there is a Symbolic Link anywhere in the path, only if the specific file is.

参数:
file - the file to check
返回:
true if the file is a Symbolic Link
抛出:
IOException - if an IO error occurs while checking the file
从以下版本开始:
Commons IO 2.0

readLines

public static List<String> readLines(File file,
                                     String encoding)
                              throws IOException
Reads the contents of a file line by line to a List of Strings. The file is always closed.

参数:
file - the file to read, must not be null
encoding - the encoding to use, null means platform default
返回:
the list of Strings representing each line in the file, never null
抛出:
IOException - in case of an I/O error
UnsupportedEncodingException - if the encoding is not supported by the VM
从以下版本开始:
Commons IO 1.1

readLines

public static List<String> readLines(File file)
                              throws IOException
Reads the contents of a file line by line to a List of Strings using the default encoding for the VM. The file is always closed.

参数:
file - the file to read, must not be null
返回:
the list of Strings representing each line in the file, never null
抛出:
IOException - in case of an I/O error
从以下版本开始:
Commons IO 1.3

readLines

public static List<String> readLines(InputStream input)
                              throws IOException
Get the contents of an InputStream as a list of Strings, one entry per line, using the default character encoding of the platform.

This method buffers the input internally, so there is no need to use a BufferedInputStream.

参数:
input - the InputStream to read from, not null
返回:
the list of Strings, never null
抛出:
NullPointerException - if the input is null
IOException - if an I/O error occurs
从以下版本开始:
Commons IO 1.1

readLines

public static List<String> readLines(InputStream input,
                                     String encoding)
                              throws IOException
Get the contents of an InputStream as a list of Strings, one entry per line, using the specified character encoding.

Character encoding names can be found at IANA.

This method buffers the input internally, so there is no need to use a BufferedInputStream.

参数:
input - the InputStream to read from, not null
encoding - the encoding to use, null means platform default
返回:
the list of Strings, never null
抛出:
NullPointerException - if the input is null
IOException - if an I/O error occurs
从以下版本开始:
Commons IO 1.1

readLines

public static List<String> readLines(Reader input)
                              throws IOException
Get the contents of a Reader as a list of Strings, one entry per line.

This method buffers the input internally, so there is no need to use a BufferedReader.

参数:
input - the Reader to read from, not null
返回:
the list of Strings, never null
抛出:
NullPointerException - if the input is null
IOException - if an I/O error occurs
从以下版本开始:
Commons IO 1.1

openInputStream

public static FileInputStream openInputStream(File file)
                                       throws IOException
Opens a FileInputStream for the specified file, providing better error messages than simply calling new FileInputStream(file).

At the end of the method either the stream will be successfully opened, or an exception will have been thrown.

An exception is thrown if the file does not exist. An exception is thrown if the file object exists but is a directory. An exception is thrown if the file exists but cannot be read.

参数:
file - the file to open for input, must not be null
返回:
a new FileInputStream for the specified file
抛出:
FileNotFoundException - if the file does not exist
IOException - if the file object is a directory
IOException - if the file cannot be read
从以下版本开始:
Commons IO 1.3


Copyright © 2015. All Rights Reserved.