public class FileUtil extends Object
| Constructor and Description |
|---|
FileUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
append(CharSequence data,
File file)
追加String到File.
|
static BufferedReader |
asBufferedReader(Path path) |
static BufferedReader |
asBufferedReader(String fileName)
获取File的BufferedReader.
|
static BufferedWriter |
asBufferedWriter(Path path)
获取File的BufferedWriter.
|
static BufferedWriter |
asBufferedWriter(String fileName)
获取File的BufferedWriter.
|
static InputStream |
asInputStream(File file)
打开文件为InputStream.
|
static InputStream |
asInputStream(Path path)
打开文件为InputStream.
|
static InputStream |
asInputStream(String fileName)
打开文件为InputStream.
|
static OutputStream |
asOututStream(File file)
打开文件为OutputStream.
|
static OutputStream |
asOututStream(Path path)
打开文件为OutputStream.
|
static OutputStream |
asOututStream(String fileName)
打开文件为OutputStream.
|
static void |
copy(File from,
File to)
复制文件或目录, not following links.
|
static void |
copy(Path from,
Path to)
复制文件或目录, not following links.
|
static void |
copyDir(File from,
File to)
复制目录
|
static void |
copyDir(Path from,
Path to)
复制目录
|
static void |
copyFile(File from,
File to)
文件复制.
|
static void |
copyFile(Path from,
Path to)
文件复制.
|
static Path |
createTempDir()
在临时目录创建临时目录,命名为${毫秒级时间戳}-${同一毫秒内的随机数}.
|
static Path |
createTempFile()
在临时目录创建临时文件,命名为tmp-${random.nextLong()}.tmp
|
static Path |
createTempFile(String prefix,
String suffix)
在临时目录创建临时文件,命名为${prefix}${random.nextLong()}${suffix}
|
static void |
deleteDir(File dir)
删除目录及所有子目录/文件
|
static void |
deleteDir(Path dir)
删除目录及所有子目录/文件
|
static void |
deleteFile(File file)
删除文件.
|
static void |
deleteFile(Path path)
删除文件.
|
static String |
getFileExtension(File file)
获取文件名的扩展名部分(不包含.)
|
static String |
getFileExtension(String fullName)
获取文件名的扩展名部分(不包含.)
|
static String |
getFileName(String fullName)
获取文件名(不包含路径)
|
static boolean |
isDirExists(File dir)
判断目录是否存在, from Jodd
|
static boolean |
isDirExists(Path dirPath) |
static boolean |
isDirExists(String dirPath)
判断目录是否存在, from Jodd
|
static boolean |
isFileExists(File file)
判断文件是否存在, from Jodd.
|
static boolean |
isFileExists(Path path)
判断文件是否存在, from Jodd.
|
static boolean |
isFileExists(String fileName)
判断文件是否存在, from Jodd.
|
static void |
makesureDirExists(File file)
确保目录存在, 如不存在则创建
|
static void |
makesureDirExists(Path dirPath)
确保目录存在, 如不存在则创建.
|
static void |
makesureDirExists(String dirPath)
确保目录存在, 如不存在则创建
|
static void |
makesureParentDirExists(File file)
确保父目录及其父目录直到根目录都已经创建.
|
static void |
moveDir(File from,
File to)
目录移动/重命名
|
static void |
moveFile(File from,
File to)
文件移动/重命名.
|
static void |
moveFile(Path from,
Path to)
文件移动/重命名.
|
static byte[] |
toByteArray(File file)
读取文件到byte[].
|
static List<String> |
toLines(File file)
读取文件的每行内容到List
|
static String |
toString(File file)
读取文件到String.
|
static void |
touch(File file)
创建文件或更新时间戳.
|
static void |
touch(String filePath)
创建文件或更新时间戳.
|
static void |
write(CharSequence data,
File file)
简单写入String到File.
|
public static byte[] toByteArray(File file) throws IOException
IOExceptionFiles#readAllBytes}public static String toString(File file) throws IOException
IOExceptionpublic static List<String> toLines(File file) throws IOException
IOExceptionFiles#readAllLines}public static void write(CharSequence data, File file) throws IOException
IOExceptionpublic static void append(CharSequence data, File file) throws IOException
IOExceptionpublic static InputStream asInputStream(String fileName) throws IOException
IOExceptionFiles#newInputStream}public static InputStream asInputStream(File file) throws IOException
IOExceptionFiles#newInputStream}public static InputStream asInputStream(Path path) throws IOException
IOExceptionFiles#newInputStream}public static OutputStream asOututStream(String fileName) throws IOException
IOExceptionFiles#newOutputStream}public static OutputStream asOututStream(File file) throws IOException
IOExceptionFiles#newOutputStream}public static OutputStream asOututStream(Path path) throws IOException
IOExceptionFiles#newOutputStream}public static BufferedReader asBufferedReader(String fileName) throws IOException
IOExceptionFiles#newBufferedReader}public static BufferedReader asBufferedReader(Path path) throws IOException
IOExceptionpublic static BufferedWriter asBufferedWriter(String fileName) throws IOException
IOExceptionFiles#newBufferedWriter}public static BufferedWriter asBufferedWriter(Path path) throws IOException
IOExceptionFiles#newBufferedWriter}public static void copy(File from, File to) throws IOException
from - 如果为null,或者是不存在的文件或目录,抛出异常.to - 如果为null,或者from是目录而to是已存在文件,或相反IOExceptionpublic static void copy(Path from, Path to) throws IOException
from - 如果为null,或者是不存在的文件或目录,抛出异常.to - 如果为null,或者from是目录而to是已存在文件,或相反IOExceptionpublic static void copyFile(File from, File to) throws IOException
from - 如果为null,或文件不存在或者是目录,,抛出异常to - 如果to为null,或文件存在但是一个目录,抛出异常IOExceptionFiles#copy}public static void copyFile(Path from, Path to) throws IOException
from - 如果为null,或文件不存在或者是目录,,抛出异常to - 如果to为null,或文件存在但是一个目录,抛出异常IOExceptionpublic static void copyDir(File from, File to) throws IOException
IOExceptionpublic static void copyDir(Path from, Path to) throws IOException
IOExceptionpublic static void moveFile(File from, File to) throws IOException
IOExceptionFiles#move}public static void moveFile(Path from, Path to) throws IOException
IOExceptionFiles#move}public static void moveDir(File from, File to) throws IOException
IOExceptionpublic static void touch(String filePath) throws IOException
IOExceptioncom.google.common.io.Files#touch}public static void touch(File file) throws IOException
IOExceptioncom.google.common.io.Files#touch}public static void deleteFile(File file) throws IOException
IOExceptionpublic static void deleteFile(Path path) throws IOException
IOExceptionpublic static void deleteDir(Path dir) throws IOException
IOExceptionFiles#walkFileTree}public static void deleteDir(File dir) throws IOException
IOExceptionpublic static boolean isDirExists(String dirPath)
public static boolean isDirExists(Path dirPath)
public static boolean isDirExists(File dir)
public static void makesureDirExists(String dirPath) throws IOException
IOExceptionpublic static void makesureDirExists(File file) throws IOException
IOExceptionpublic static void makesureDirExists(Path dirPath) throws IOException
IOExceptionFiles#createDirectories}public static void makesureParentDirExists(File file) throws IOException
IOExceptionpublic static boolean isFileExists(String fileName)
Files#exists},
Files#isRegularFile}public static boolean isFileExists(File file)
Files#exists},
Files#isRegularFile}public static boolean isFileExists(Path path)
Files#exists},
Files#isRegularFile}public static Path createTempDir() throws IOException
IOExceptionFiles#createTempDirectory}public static Path createTempFile() throws IOException
IOExceptionFiles#createTempFile}public static Path createTempFile(String prefix, String suffix) throws IOException
IOExceptionFiles#createTempFile}public static String getFileExtension(File file)
com.google.common.io.Files#getFileExtension}Copyright © 2018. All rights reserved.