public class FileUtils
extends java.lang.Object
| 构造器和说明 |
|---|
FileUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
copyFile(java.lang.String sourceFilePath,
java.lang.String destFilePath)
Copy file
|
static void |
copyFileFromInputStream(java.io.InputStream is,
java.lang.String newPath)
Copy File from InputStream
|
static void |
copyFileFromPath(java.lang.String oldPath,
java.lang.String newPath)
Copy file
|
static void |
createFile(java.lang.String path,
java.lang.String fileName)
Create New File
|
static boolean |
deleteFile(java.lang.String filePath)
Delete the File no matter it's a file or folder.If the file path is a folder,this method
will delete all the file in the folder.
|
static java.lang.String |
getCurrentDataPath(android.content.Context context) |
static java.lang.String |
getCurrentDataPath(android.content.Context context,
java.lang.String folderName) |
static java.lang.String |
getFileExtension(java.lang.String filePath)
Get extension of the file
|
static java.lang.String |
getFileName(java.lang.String filePath)
Get the file name with extension
|
static java.lang.String |
getFileNameWithoutExtension(java.lang.String filePath)
Get only the file name without extension
|
static long |
getFileSize(java.lang.String path)
Get size of the file
|
static java.lang.String |
getFolderName(java.lang.String filePath)
Get folder name from the filepath
|
static boolean |
isFileExist(java.lang.String filePath)
Indicates if the file represents a file exists.
|
static boolean |
isFolderExist(java.lang.String directoryPath)
Indicates if the file represents a directory exists.
|
static boolean |
makeDirs(java.lang.String dirPath)
Create Folder
|
static java.lang.String |
readFile(java.io.File fileName)
Read file to String with default charset 'UTF-8'
|
static java.lang.String |
readFile(java.io.File fileName,
java.lang.String charset)
Read file to String
|
static java.lang.String |
readFile(java.lang.String fileName)
Read file to String with default charset 'UTF-8'
|
static java.lang.String |
readFile(java.lang.String fileName,
java.lang.String charset)
Read file to String
|
static boolean |
writeFile(java.io.File file,
java.io.InputStream stream)
write file, the bytes will be written to the begin of the file
|
static boolean |
writeFile(java.io.File file,
java.io.InputStream stream,
boolean append)
Write file
|
static boolean |
writeFile(java.lang.String filePath,
java.io.InputStream stream)
Write file with InputStream
|
static boolean |
writeFile(java.lang.String filePath,
java.io.InputStream stream,
boolean append)
write file
|
static boolean |
writeFile(java.lang.String filePath,
java.lang.String content)
If the file already exists, it will be truncated.
|
static boolean |
writeFile(java.lang.String filePath,
java.lang.String content,
boolean append)
If
append is true and the file already exists, it will be appended to; otherwise
it will be truncated. |
static void |
WriteStreamAppendByFileOutputStream(java.lang.String fileName,
java.lang.String content)
Append file using FileOutputStream
|
static void |
writeStreamAppendByFileWriter(java.lang.String fileName,
java.lang.String content)
Append file using FileWriter
|
static void |
WriteStreamAppendByRandomAccessFile(java.lang.String fileName,
java.lang.String content)
Append file using RandomAccessFile
|
public static java.lang.String readFile(java.lang.String fileName,
java.lang.String charset)
throws java.io.IOException
fileName - charset - java.io.IOExceptionpublic static java.lang.String readFile(java.lang.String fileName)
throws java.io.IOException
fileName - java.io.IOExceptionpublic static java.lang.String readFile(java.io.File fileName)
throws java.io.IOException
fileName - java.io.IOExceptionpublic static java.lang.String readFile(java.io.File fileName,
java.lang.String charset)
throws java.io.IOException
fileName - charset - java.io.IOExceptionpublic static java.lang.String getCurrentDataPath(android.content.Context context)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String getCurrentDataPath(android.content.Context context,
java.lang.String folderName)
throws java.io.IOException
java.io.IOExceptionpublic static void createFile(java.lang.String path,
java.lang.String fileName)
throws java.io.IOException
path - Folder NamefileName - File Namejava.io.IOExceptionpublic static void WriteStreamAppendByFileOutputStream(java.lang.String fileName,
java.lang.String content)
throws java.io.IOException
fileName - content - java.io.IOExceptionpublic static void writeStreamAppendByFileWriter(java.lang.String fileName,
java.lang.String content)
throws java.io.IOException
fileName - content - java.io.IOExceptionpublic static void WriteStreamAppendByRandomAccessFile(java.lang.String fileName,
java.lang.String content)
throws java.io.IOException
fileName - content - java.io.IOExceptionpublic static void copyFileFromPath(java.lang.String oldPath,
java.lang.String newPath)
throws java.io.IOException
oldPath - StringnewPath - Stringjava.io.IOExceptionpublic static void copyFileFromInputStream(java.io.InputStream is,
java.lang.String newPath)
throws java.io.IOException
is - InputStreamnewPath - Stringjava.io.IOExceptionpublic static boolean writeFile(java.lang.String filePath,
java.lang.String content,
boolean append)
throws java.io.IOException
append is true and the file already exists, it will be appended to; otherwise
it will be truncated. The file will be created if it does not exist.filePath - content - append - Indicates whether or not to append to an existing file.java.lang.RuntimeException - if an error occurs while operator FileWriterjava.io.IOExceptionpublic static boolean writeFile(java.lang.String filePath,
java.lang.String content)
throws java.io.IOException
filePath - content - java.io.IOExceptionpublic static boolean writeFile(java.lang.String filePath,
java.io.InputStream stream)
filePath - stream - public static boolean writeFile(java.lang.String filePath,
java.io.InputStream stream,
boolean append)
filePath - the file to be opened for writing.stream - the input streamappend - if true, then bytes will be written to the end of the file rather than the beginningjava.lang.RuntimeException - if an error occurs while operator FileOutputStreampublic static boolean writeFile(java.io.File file,
java.io.InputStream stream)
file - stream - #writeFile(java.io.File, java.io.InputStream, boolean)}public static boolean writeFile(java.io.File file,
java.io.InputStream stream,
boolean append)
file - the file to be opened for writing.stream - the input streamappend - if true, then bytes will be written to the end of the file rather than the beginningjava.lang.RuntimeException - if an error occurs while operator FileOutputStreampublic static boolean copyFile(java.lang.String sourceFilePath,
java.lang.String destFilePath)
sourceFilePath - destFilePath - java.lang.RuntimeException - if an error occurs while operator FileOutputStreampublic static java.lang.String getFileNameWithoutExtension(java.lang.String filePath)
filePath - public static java.lang.String getFileName(java.lang.String filePath)
filePath - public static java.lang.String getFolderName(java.lang.String filePath)
filePath - public static java.lang.String getFileExtension(java.lang.String filePath)
filePath - public static boolean makeDirs(java.lang.String dirPath)
dirPath - public static boolean isFileExist(java.lang.String filePath)
filePath - public static boolean isFolderExist(java.lang.String directoryPath)
directoryPath - public static boolean deleteFile(java.lang.String filePath)
throws java.io.IOException
filePath - java.io.IOExceptionpublic static long getFileSize(java.lang.String path)
path -