程序包 com.sh.util
类 FileUtil
java.lang.Object
com.sh.util.FileUtil
Description: 文件操作工具类
Title:首亨软件 - CRM、TSS、ERP等信息化管理软件
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static void复制文件static voidcopyFile2Dir(File srcFile, File destDir) 复制文件到指定文件夹static booleancopyInputStream2File(InputStream is, File file) static booleancopyInputStream2File(InputStream is, File file, boolean disconnect) 将流复制到文件中static booleandeleteFileByRes(String path) 删除资源服务器上的文件static StringgetFilecharset(File sourceFile) 得到文件的编码static StringgetFileDocType(String fileName) 获取类型static InputStreamgetFileInputStream(String path) 根据路径获取文件流对象static InputStream从网络上获取文件流static InputStream从资源服务器上获取文件流static StringgetFileNameByPath(String path) static StringreadFileContent(File file) static StringreadFileContent(File file, String charset) static StringreadFileContent(File file, String charset, String breakLine) 读取文件内容static StringreadFileContent(InputStream inputStream) static StringreadFileContent(InputStream inputStream, String charset) static StringreadFileContent(InputStream inputStream, String charset, String breakLine) static StringreadFileContent(String filePath) 读取文件内容static StringreadFileContentByClassLoader(String resource) static StringreadFileContentByClassLoader(String resource, String enterChar, String charset) 从class路径中读取内容static StringreadFileLastNLine(File file, int numRead) 读取文件最后几行static StringreadFileLastNLine(String filePath, int numRead) 读取文件最后几行static ObjectreadFileObjectContent(File file) 读取通过writeObjectFile写到文件中的对象static ObjectreadFileObjectContent(String filePath) 读取通过writeObjectFile写到文件中的对象static StringreadJarFileContent(String fileName) 从全部JAR包中读取文件static StringreadJarFileContent(String fileName, String jarNamePrefix) 从JAR包中读取文件static String[]sendFileToRes(File file, String path) 发送文件到资源服务器static String[]sendFileToRes(InputStream is, String path) 传送文件到资源服务器static String[]sendFileToRes(String url, String path) 上传文件到资源服务嚣static String文件路径转化为资源服务器路径static String文件路径转化为资源服务器路径static booleanwriteFileContent(File file, String content) static booleanwriteFileContent(File file, String content, String charset) 写文件static booleanwriteObjectFile(File file, Object obj) 将对象保存到文件中,需要用readFileObjectContent方法来读取还原static booleanwriteObjectFile(String filePath, Object obj) 将对象保存到文件中,需要用readFileObjectContent方法来读取还原
-
构造器详细资料
-
FileUtil
public FileUtil()
-
-
方法详细资料
-
copyFile
复制文件- 参数:
srcFile- FiledestFile- File- 抛出:
IOException- IOException
-
copyFile2Dir
复制文件到指定文件夹- 参数:
srcFile- FiledestDir- File- 抛出:
IOException- IOException
-
copyInputStream2File
-
copyInputStream2File
将流复制到文件中- 参数:
is- InputStreamfile- Filedisconnect- 是否自动关闭流- 返回:
- boolean
-
readFileContent
读取文件内容- 参数:
filePath- 文件路径- 返回:
- String
-
readFileContentByClassLoader
-
readFileContentByClassLoader
public static String readFileContentByClassLoader(String resource, String enterChar, String charset) 从class路径中读取内容- 参数:
resource- classpath路径enterChar- Stringcharset- String- 返回:
- String
-
readFileContent
-
readFileContent
-
readFileContent
读取文件内容- 参数:
file- 文件对象charset- 字符集,默认为系统字符,如:GBK、UTF-8breakLine- String- 返回:
- String
-
readFileContent
-
readFileContent
-
readFileContent
-
getFilecharset
得到文件的编码- 参数:
sourceFile- File- 返回:
- 文件的编码
-
writeFileContent
-
writeFileContent
写文件- 参数:
file- Filecontent- Stringcharset- String- 返回:
- boolean
-
readJarFileContent
从全部JAR包中读取文件- 参数:
fileName- 文件名- 返回:
- String
-
readJarFileContent
从JAR包中读取文件- 参数:
fileName- 文件名jarNamePrefix- 查找JAR包前缀- 返回:
- String
-
getFileDocType
获取类型- 参数:
fileName- String- 返回:
- String
-
toResPath
文件路径转化为资源服务器路径- 参数:
path-- 返回:
-
toResPath
文件路径转化为资源服务器路径- 参数:
path-- 返回:
-
sendFileToRes
发送文件到资源服务器- 参数:
file- 文件对象path- 资源服务器上存放路径- 返回:
- String[]
-
sendFileToRes
上传文件到资源服务嚣- 参数:
url- URL路径path- 资源服务嚣路径- 返回:
- String[]
-
sendFileToRes
传送文件到资源服务器- 参数:
is- 文件流path- 保存路径- 返回:
- String[]
-
getFileInputStream
根据路径获取文件流对象- 参数:
path- 本地文件路径或网络文件路径,也可以直接是资源服务器上的相对路径- 返回:
-
getFileInputStreamByHttp
从网络上获取文件流- 参数:
path- 文件路径 http路径- 返回:
- InputStream
-
getFileInputStreamByRes
从资源服务器上获取文件流- 参数:
path- 文件路径- 返回:
- InputStream
-
deleteFileByRes
删除资源服务器上的文件- 参数:
path- String- 返回:
- boolean
-
readFileLastNLine
读取文件最后几行- 参数:
filePath- 文件路径numRead- 最后读取行数- 返回:
- String
-
readFileLastNLine
读取文件最后几行- 参数:
file- 文件numRead- 最后读取行数- 返回:
- String
-
getFileNameByPath
-
writeObjectFile
将对象保存到文件中,需要用readFileObjectContent方法来读取还原- 参数:
filePath- 保存文件路径obj- 序列化对象- 返回:
- boolean
-
writeObjectFile
将对象保存到文件中,需要用readFileObjectContent方法来读取还原- 参数:
file- 保存文件obj- 序列化对象- 返回:
- boolean
-
readFileObjectContent
读取通过writeObjectFile写到文件中的对象- 参数:
filePath- 文件路径- 返回:
- Object
-
readFileObjectContent
读取通过writeObjectFile写到文件中的对象- 参数:
file- 文件- 返回:
- Object
-