public class FileUtils extends Object
#readFile(String) read file#readFileToList(String) read file to string listwriteFile(String, String, boolean) write file from StringwriteFile(String, String) write file from StringwriteFile(String, List, boolean) write file from String ListwriteFile(String, List) write file from String ListwriteFile(String, InputStream) write filewriteFile(String, InputStream, boolean) write filewriteFile(File, InputStream) write filewriteFile(File, InputStream, boolean) write file| 限定符和类型 | 字段和说明 |
|---|---|
static String |
FILE_EXTENSION_SEPARATOR |
| 构造器和说明 |
|---|
FileUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
copyFile(String sourceFilePath,
String destFilePath)
copy file
|
static boolean |
deleteFile(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 String |
getFileExtension(String filePath)
get suffix of file from path
getFileExtension(null) = ""
getFileExtension("") = ""
getFileExtension(" ") = " "
getFileExtension("a.mp3") = "mp3"
getFileExtension("a.b.rmvb") = "rmvb"
getFileExtension("abc") = ""
getFileExtension("c:\\") = ""
getFileExtension("c:\\a") = ""
getFileExtension("c:\\a.b") = "b"
getFileExtension("c:a.txt\\a") = ""
getFileExtension("/home/admin") = ""
getFileExtension("/home/admin/a.txt/b") = ""
getFileExtension("/home/admin/a.txt/b.mp3") = "mp3"
|
static String |
getFileName(String filePath)
get file name from path, include suffix
getFileName(null) = null
getFileName("") = ""
getFileName(" ") = " "
getFileName("a.mp3") = "a.mp3"
getFileName("a.b.rmvb") = "a.b.rmvb"
getFileName("abc") = "abc"
getFileName("c:\\") = ""
getFileName("c:\\a") = "a"
getFileName("c:\\a.b") = "a.b"
getFileName("c:a.txt\\a") = "a"
getFileName("/home/admin") = "admin"
getFileName("/home/admin/a.txt/b.mp3") = "b.mp3"
|
static String |
getFileNameWithoutExtension(String filePath)
get file name from path, not include suffix
getFileNameWithoutExtension(null) = null
getFileNameWithoutExtension("") = ""
getFileNameWithoutExtension(" ") = " "
getFileNameWithoutExtension("abc") = "abc"
getFileNameWithoutExtension("a.mp3") = "a"
getFileNameWithoutExtension("a.b.rmvb") = "a.b"
getFileNameWithoutExtension("c:\\") = ""
getFileNameWithoutExtension("c:\\a") = "a"
getFileNameWithoutExtension("c:\\a.b") = "a"
getFileNameWithoutExtension("c:a.txt\\a") = "a"
getFileNameWithoutExtension("/home/admin") = "admin"
getFileNameWithoutExtension("/home/admin/a.txt/b.mp3") = "b"
|
static long |
getFileSize(String path)
get file size
if path is null or empty, return -1
if path exist and it is a file, return file size, else return -1
|
static String |
getFolderName(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 |
isFileExist(String filePath)
Indicates if this file represents a file on the underlying file system.
|
static boolean |
isFolderExist(String directoryPath)
Indicates if this file represents a directory on the underlying file system.
|
static boolean |
makeDirs(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(String filePath) |
static StringBuilder |
readFile(String filePath,
String charsetName)
read file
|
static List<String> |
readFileToList(String filePath,
String charsetName)
read file to string list, a element of list is a line
|
static boolean |
writeFile(File file,
InputStream stream)
write file, the bytes will be written to the begin of the file
|
static boolean |
writeFile(File file,
InputStream stream,
boolean append)
write file
|
static boolean |
writeFile(String filePath,
InputStream stream)
write file, the bytes will be written to the begin of the file
|
static boolean |
writeFile(String filePath,
InputStream stream,
boolean append)
write file
|
static boolean |
writeFile(String filePath,
List<String> contentList)
write file, the string list will be written to the begin of the file
|
static boolean |
writeFile(String filePath,
List<String> contentList,
boolean append)
write file
|
static boolean |
writeFile(String filePath,
String content)
write file, the string will be written to the begin of the file
|
static boolean |
writeFile(String filePath,
String content,
boolean append)
write file
|
public static StringBuilder readFile(String filePath, String charsetName)
filePath - charsetName - The name of a supported charsetRuntimeException - if an error occurs while operator BufferedReaderpublic static boolean writeFile(String filePath, 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 itRuntimeException - if an error occurs while operator FileWriterpublic static boolean writeFile(String filePath, List<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 itRuntimeException - if an error occurs while operator FileWriterpublic static boolean writeFile(String filePath, String content)
filePath - content - public static boolean writeFile(String filePath, List<String> contentList)
filePath - contentList - public static boolean writeFile(String filePath, InputStream stream)
filePath - stream - #writeFile(String, InputStream, boolean)}public static boolean writeFile(String filePath, 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 beginningRuntimeException - if an error occurs while operator FileOutputStreampublic static boolean writeFile(File file, InputStream stream)
file - stream - #writeFile(File, InputStream, boolean)}public static boolean writeFile(File file, 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 beginningRuntimeException - if an error occurs while operator FileOutputStreampublic static boolean copyFile(String sourceFilePath, String destFilePath)
sourceFilePath - destFilePath - RuntimeException - if an error occurs while operator FileOutputStreampublic static List<String> readFileToList(String filePath, String charsetName)
filePath - charsetName - The name of a supported charsetRuntimeException - if an error occurs while operator BufferedReaderpublic static String getFileNameWithoutExtension(String filePath)
getFileNameWithoutExtension(null) = null
getFileNameWithoutExtension("") = ""
getFileNameWithoutExtension(" ") = " "
getFileNameWithoutExtension("abc") = "abc"
getFileNameWithoutExtension("a.mp3") = "a"
getFileNameWithoutExtension("a.b.rmvb") = "a.b"
getFileNameWithoutExtension("c:\\") = ""
getFileNameWithoutExtension("c:\\a") = "a"
getFileNameWithoutExtension("c:\\a.b") = "a"
getFileNameWithoutExtension("c:a.txt\\a") = "a"
getFileNameWithoutExtension("/home/admin") = "admin"
getFileNameWithoutExtension("/home/admin/a.txt/b.mp3") = "b"
filePath - public static String getFileName(String filePath)
getFileName(null) = null
getFileName("") = ""
getFileName(" ") = " "
getFileName("a.mp3") = "a.mp3"
getFileName("a.b.rmvb") = "a.b.rmvb"
getFileName("abc") = "abc"
getFileName("c:\\") = ""
getFileName("c:\\a") = "a"
getFileName("c:\\a.b") = "a.b"
getFileName("c:a.txt\\a") = "a"
getFileName("/home/admin") = "admin"
getFileName("/home/admin/a.txt/b.mp3") = "b.mp3"
filePath - public static String getFolderName(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 String getFileExtension(String filePath)
getFileExtension(null) = ""
getFileExtension("") = ""
getFileExtension(" ") = " "
getFileExtension("a.mp3") = "mp3"
getFileExtension("a.b.rmvb") = "rmvb"
getFileExtension("abc") = ""
getFileExtension("c:\\") = ""
getFileExtension("c:\\a") = ""
getFileExtension("c:\\a.b") = "b"
getFileExtension("c:a.txt\\a") = ""
getFileExtension("/home/admin") = ""
getFileExtension("/home/admin/a.txt/b") = ""
getFileExtension("/home/admin/a.txt/b.mp3") = "mp3"
filePath - public static boolean makeDirs(String filePath)
filePath - getFolderName(String) return null, return falsejava.io.File#makeFolderpublic static boolean makeFolders(String filePath)
filePath - makeDirs(String)public static boolean isFileExist(String filePath)
filePath - public static boolean isFolderExist(String directoryPath)
directoryPath - public static boolean deleteFile(String path)
path - public static long getFileSize(String path)
path - Copyright © 2012-2014. All Rights Reserved.