public abstract class FileUtil
extends java.lang.Object
| 限定符和类型 | 字段和说明 |
|---|---|
static java.lang.String[] |
AUDIO_EXTENSIONS |
static java.lang.String[] |
VIDEO_EXTENSIONS |
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
copyFile(java.lang.String sourceFilePath,
java.lang.String destFilePath)
copy file
|
static boolean |
deleteFile(java.lang.String path)
delete file or directory
if path is null or empty, return true
if path not exist, return true
if path exist, delete recursion. return true
|
static java.lang.String |
formatFileSize(long size)
转换文件大小单位(b/kb/mb/gb) **
|
static long |
getDirectoryFileCount(java.io.File f)
获取文件个数 **
|
static long |
getDirectorySize(java.io.File f)
获取文件夹大小 **
|
static java.lang.String |
getFileExtension(java.io.File f)
获取文件后缀
|
static java.lang.String |
getFileNameNoExtension(java.lang.String filename) |
static long |
getFileSize(java.io.File f)
获取文件大小 **
|
static java.lang.String |
getFolderName(java.lang.String filePath)
get folder name from path
getFolderName(null) = null
getFolderName("") = ""
getFolderName(" ") = ""
getFolderName("a.mp3") = ""
getFolderName("a.b.rmvb") = ""
getFolderName("abc") = ""
getFolderName("c:\\") = "c:"
getFolderName("c:\\a") = "c:"
getFolderName("c:\\a.b") = "c:"
getFolderName("c:a.txt\\a") = "c:a.txt"
getFolderName("c:a\\b\\c\\d.txt") = "c:a\\b\\c"
getFolderName("/home/admin") = "/home"
getFolderName("/home/admin/a.txt/b.mp3") = "/home/admin/a.txt"
|
static boolean |
hasSDCard() |
static boolean |
isFileExist(java.lang.String filePath)
Indicates if this file represents a file on the underlying file system.
|
static boolean |
isFolderExist(java.lang.String directoryPath)
Indicates if this file represents a directory on the underlying file system.
|
static boolean |
isVideoOrAudio(java.io.File f)
是否是音频或者视频
|
static boolean |
makeDirs(java.lang.String filePath)
Creates the directory named by the trailing filename of this file, including the complete directory path required
to create this directory.
|
static boolean |
makeFolders(java.lang.String filePath) |
static java.lang.StringBuilder |
readFile(java.lang.String filePath,
java.lang.String charsetName)
read file
|
static java.util.List<java.lang.String> |
readFileToList(java.lang.String filePath,
java.lang.String charsetName)
read file to string list, a element of list is a line
|
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, the bytes will be written to the begin of the file
|
static boolean |
writeFile(java.lang.String filePath,
java.io.InputStream stream,
boolean append)
write file
|
static boolean |
writeFile(java.lang.String filePath,
java.util.List<java.lang.String> contentList)
write file, the string list will be written to the begin of the file
|
static boolean |
writeFile(java.lang.String filePath,
java.util.List<java.lang.String> contentList,
boolean append)
write file
|
static boolean |
writeFile(java.lang.String filePath,
java.lang.String content)
write file, the string will be written to the begin of the file
|
static boolean |
writeFile(java.lang.String filePath,
java.lang.String content,
boolean append)
write file
|
public static final java.lang.String[] VIDEO_EXTENSIONS
public static final java.lang.String[] AUDIO_EXTENSIONS
public static boolean isVideoOrAudio(java.io.File f)
public static boolean copyFile(java.lang.String sourceFilePath,
java.lang.String destFilePath)
public static java.util.List<java.lang.String> readFileToList(java.lang.String filePath,
java.lang.String charsetName)
filePath - charsetName - The name of a supported charsetjava.lang.RuntimeException - if an error occurs while operator BufferedReaderpublic static java.lang.StringBuilder readFile(java.lang.String filePath,
java.lang.String charsetName)
filePath - charsetName - The name of a supported charsetjava.lang.RuntimeException - if an error occurs while operator BufferedReaderpublic static boolean writeFile(java.lang.String filePath,
java.lang.String content,
boolean append)
filePath - content - append - is append, if true, write to the end of file, else clear content of file and write into itjava.lang.RuntimeException - if an error occurs while operator FileWriterpublic static boolean writeFile(java.lang.String filePath,
java.util.List<java.lang.String> contentList,
boolean append)
filePath - contentList - append - is append, if true, write to the end of file, else clear content of file and write into itjava.lang.RuntimeException - if an error occurs while operator FileWriterpublic 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 writeFile(java.lang.String filePath,
java.lang.String content)
filePath - content - public static boolean writeFile(java.lang.String filePath,
java.util.List<java.lang.String> contentList)
filePath - contentList - public static boolean writeFile(java.lang.String filePath,
java.io.InputStream stream)
filePath - stream - #writeFile(String, InputStream, boolean)}public static boolean writeFile(java.lang.String filePath,
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 writeFile(java.io.File file,
java.io.InputStream stream)
file - stream - #writeFile(File, InputStream, boolean)}public static boolean makeDirs(java.lang.String filePath)
filePath - FileUtils#getFolderName(String) return null, return falsejava.io.File#makeFolderpublic static java.lang.String getFolderName(java.lang.String filePath)
getFolderName(null) = null
getFolderName("") = ""
getFolderName(" ") = ""
getFolderName("a.mp3") = ""
getFolderName("a.b.rmvb") = ""
getFolderName("abc") = ""
getFolderName("c:\\") = "c:"
getFolderName("c:\\a") = "c:"
getFolderName("c:\\a.b") = "c:"
getFolderName("c:a.txt\\a") = "c:a.txt"
getFolderName("c:a\\b\\c\\d.txt") = "c:a\\b\\c"
getFolderName("/home/admin") = "/home"
getFolderName("/home/admin/a.txt/b.mp3") = "/home/admin/a.txt"
filePath - public static boolean makeFolders(java.lang.String filePath)
filePath - makeDirs(String)public static boolean isFileExist(java.lang.String filePath)
filePath - public static boolean isFolderExist(java.lang.String directoryPath)
directoryPath - public static java.lang.String getFileExtension(java.io.File f)
public static java.lang.String getFileNameNoExtension(java.lang.String filename)
public static long getFileSize(java.io.File f)
throws java.lang.Exception
java.lang.Exceptionpublic static long getDirectorySize(java.io.File f)
throws java.lang.Exception
java.lang.Exceptionpublic static java.lang.String formatFileSize(long size)
public static long getDirectoryFileCount(java.io.File f)
public static boolean deleteFile(java.lang.String path)
public static boolean hasSDCard()