public class CommonFileUtils extends Object
| Constructor and Description |
|---|
CommonFileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
closeFileStream(InputStream inputStream,
String filePath)
关闭对应的文件流
|
static byte[] |
getFileContentByte(InputStream inputStream,
long offset,
int length) |
static byte[] |
getFileContentByte(String filePath)
获取小文件的全部内容
|
static byte[] |
getFileContentByte(String filePath,
long offset,
int length)
获取文件指定块的内容
|
static FileInputStream |
getFileInputStream(String filePath)
打开对应的文件,并返回文件输入流
|
static long |
getFileLastModified(String filePath)
获取文件上次的修改时间
|
static long |
getFileLength(String filePath)
获取文件长度,单位为字节
|
static boolean |
isLegalFile(String filePath)
判断指定路径的文件是否有效, 即文件存在,且可读
|
static void |
remove(String filePath)
删除文件
|
public static boolean isLegalFile(String filePath)
filePath - 文件路径public static long getFileLength(String filePath) throws Exception
filePath - 文件的本地路径Exception - 文件不存在或者是一个目录,则抛出异常public static FileInputStream getFileInputStream(String filePath) throws Exception
filePath - 文件路径FileNotFoundException - 如果文件不存在,则抛出异常Exceptionpublic static void closeFileStream(InputStream inputStream, String filePath)
inputStream - 待关闭的文件流filePath - 对应的文件名public static byte[] getFileContentByte(String filePath) throws Exception
filePath - 文件路径Exception - 异常public static byte[] getFileContentByte(String filePath, long offset, int length) throws Exception
filePath - 文件路径offset - 偏移量,即从哪里开始读取,单位为字节length - 读取的长度,单位为字节Exception - 异常public static byte[] getFileContentByte(InputStream inputStream, long offset, int length) throws Exception
Exceptionpublic static void remove(String filePath)
filePath - 文件路径Copyright © 2019. All rights reserved.