public class FileUtil
extends org.springframework.util.FileCopyUtils
| Modifier and Type | Class and Description |
|---|---|
static class |
FileUtil.TrueFilter
默认为true
|
| Constructor and Description |
|---|
FileUtil() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
deleteQuietly(File file)
Deletes a file, never throwing an exception.
|
static String |
getFileExtension(String fullName)
获取文件后缀名 jpg
|
static String |
getFileExtensionWithDot(String fullName)
获取文件后缀名 .jpg
|
static String |
getFilename(String path)
获取文件后缀名
|
static String |
getPathWithoutExtension(String path)
获取文件名,去除后缀名
|
static File |
getTempDir()
Returns a
File representing the system temporary directory. |
static String |
getTempDirPath()
Returns the path to the system temporary directory.
|
static List<File> |
list(File file)
扫描目录下的文件
|
static List<File> |
list(File file,
FileFilter filter)
扫描目录下的文件
|
static List<File> |
list(File file,
String... fileNamePatterns)
扫描目录下的文件
|
static List<File> |
list(File file,
String fileNamePattern)
扫描目录下的文件
|
static List<File> |
list(String path)
扫描目录下的文件
|
static List<File> |
list(String path,
FileFilter filter)
扫描目录下的文件
|
static List<File> |
list(String path,
String fileNamePattern)
扫描目录下的文件
|
static void |
moveFile(File srcFile,
File destFile)
Moves a file.
|
static List<String> |
readLines(File file)
NIO 按行读取文件
|
static List<String> |
readLines(File file,
Charset cs)
NIO 按行读取文件
|
static List<String> |
readLines(Path path)
NIO 按行读取文件
|
static List<String> |
readLines(Path path,
Charset cs)
NIO 按行读取文件
|
static List<String> |
readLines(String path)
NIO 按行读取文件
|
static List<String> |
readLines(String path,
Charset cs)
NIO 按行读取文件
|
static byte[] |
readToByteArray(File file)
Reads the contents of a file into a String.
|
static String |
readToString(File file)
Reads the contents of a file into a String.
|
static String |
readToString(File file,
Charset encoding)
Reads the contents of a file into a String.
|
static void |
toFile(InputStream in,
File file)
转成file
|
static void |
toFile(org.springframework.web.multipart.MultipartFile multipartFile,
File file)
转成file
|
static File |
toTempDir(String subDirFile)
拼接临时文件目录.
|
static String |
toTempDirPath(String subDirFile)
拼接临时文件目录.
|
static void |
writeToFile(File file,
String data)
Writes a String to a file creating the file if it does not exist.
|
static void |
writeToFile(File file,
String data,
boolean append)
Writes a String to a file creating the file if it does not exist.
|
static void |
writeToFile(File file,
String data,
Charset encoding)
Writes a String to a file creating the file if it does not exist.
|
static void |
writeToFile(File file,
String data,
Charset encoding,
boolean append)
Writes a String to a file creating the file if it does not exist.
|
public static List<File> list(String path, String fileNamePattern)
path - 路径fileNamePattern - 文件名 * 号public static List<File> list(String path, FileFilter filter)
path - 路径filter - 文件过滤public static List<File> list(File file, String fileNamePattern)
file - 文件fileNamePattern - "xxx*", "*xxx", "*xxx*" and "xxx*yyy"public static List<File> list(File file, String... fileNamePatterns)
file - 文件fileNamePatterns - "xxx*", "*xxx", "*xxx*" and "xxx*yyy"public static List<File> list(File file, FileFilter filter)
file - 文件filter - 文件过滤@Nullable public static String getFilename(@Nullable String path)
path - 文件路径@Nullable public static String getFileExtension(@Nullable String fullName)
fullName - 文件全名@Nullable public static String getFileExtensionWithDot(@Nullable String fullName)
fullName - 文件全名@Nullable public static String getPathWithoutExtension(@Nullable String path)
path - 文件public static String getTempDirPath()
public static File getTempDir()
File representing the system temporary directory.public static File toTempDir(String subDirFile)
public static String readToString(File file)
file - the file to read, must not be nullnullpublic static String readToString(File file, Charset encoding)
file - the file to read, must not be nullencoding - the encoding to use, null means platform defaultnullpublic static byte[] readToByteArray(File file)
file - the file to read, must not be nullnullpublic static void writeToFile(File file, String data)
file - the file to writedata - the content to write to the filepublic static void writeToFile(File file, String data, boolean append)
file - the file to writedata - the content to write to the fileappend - if true, then the String will be added to the
end of the file rather than overwritingpublic static void writeToFile(File file, String data, Charset encoding)
file - the file to writedata - the content to write to the fileencoding - the encoding to use, null means platform defaultpublic static void writeToFile(File file, String data, Charset encoding, boolean append)
file - the file to writedata - the content to write to the fileencoding - the encoding to use, null means platform defaultappend - if true, then the String will be added to the
end of the file rather than overwritingpublic static void toFile(org.springframework.web.multipart.MultipartFile multipartFile,
File file)
multipartFile - MultipartFilefile - Filepublic static void toFile(InputStream in, File file)
in - InputStreamfile - Filepublic static void moveFile(File srcFile, File destFile) throws IOException
When the destination file is on another file system, do a "copy and delete".
srcFile - the file to be moveddestFile - the destination fileNullPointerException - if source or destination is nullIOException - if source or destination is invalidIOException - if an IO error occurs moving the filepublic static boolean deleteQuietly(@Nullable
File file)
The difference between File.delete() and this method are:
file - file or directory to delete, can be nulltrue if the file or directory was deleted, otherwise
falsepublic static List<String> readLines(String path)
path - 文件路径public static List<String> readLines(File file)
file - 文件public static List<String> readLines(Path path)
path - 文件路径public static List<String> readLines(String path, Charset cs)
path - 文件路径cs - 字符集public static List<String> readLines(File file, Charset cs)
file - 文件cs - 字符集Copyright © 2024. All rights reserved.