public class FileUtil extends Object
| 构造器和说明 |
|---|
FileUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
copyFile(String oldPath,
String newPath)
【v1.0】复制单个文件
|
static void |
copyFolder(String oldDirPath,
String newDirPath)
复制整个文件夹内容
|
static void |
createFile(String filePath,
byte[] byteArray)
【v1.0】创建新文件。
|
static void |
createFile(String filePath,
InputStream inputStream)
【v1.0】创建新文件。
|
static void |
createFolder(String folderPath)
【v1.0】 创建单个文件夹。
|
static void |
createFolders(String folderPath)
【v1.0】创建多级文件夹。
|
static void |
createTextFile(String filePath,
String content)
【v1.0】创建新文件。
|
static void |
createTextFile(String filePath,
String content,
String Charset)
【v1.0】创建新文件。
|
static void |
delAllFile(String folderPath)
删除文件夹里面的所有文件
|
static void |
delFile(String filePath)
【v1.0】删除文件
|
static void |
delFolder(String folderPath)
删除文件夹
|
static String |
getClassLoaderPath() |
static String |
getFileName(String fullFileName)
【v1.0】返回不含扩展名的文件名 【v1.0】
|
static String |
getSystemProperties(String propertyKey)
读取system.properties中的一个配置项
|
static String |
getSystemProperties(String propertyKey,
boolean isFromCache)
读取bin/classes或WEB-INF/classes目录下的system.properties文件
|
static Properties |
getSystemPropertiesFile() |
static void |
moveAndZipFileToDir(File srcFile,
String bakupDir)
以压缩方式移动到指定目录。
|
static void |
moveAndZipFileToDir(File srcFile,
String bakupDir,
Boolean isExtentionLowerCase)
以压缩方式移动到指定目录。
|
static void |
moveFile(String oldFilePath,
String newFilePath)
【v1.0】移动文件变为新目录的文件
|
static void |
moveFolder(String oldPath,
String newPath)
移动文件夹到新文件夹
|
static void |
propFileSave(Properties properties) |
static byte[] |
readFileBytes(String filePath)
【v1.0】读取文件字节
|
static String |
readTextFile(String filePath,
String Charset)
【v1.0】读取文本文件
|
static String |
readTextFileByUTF8(String fileName) |
static byte[] |
readZipFirstFileBytes(String zipFilePath)
【v1.0】读取zip文件包中的第一个文件中的字节。
|
static byte[] |
readZipStreamFirstFileBytes(InputStream zipFile)
【v1.0】读取zip文件流中的第一个文件中的字节。
|
static void |
unZipToFolder(String zipFilePath,
String outputFolderPath)
【v1.0】Zip文件解压。
|
static void |
zip(File destFile,
File srcFile)
【v1.0】单个或多个压缩。
|
static void |
zip(String destFilePath,
String srcFilesPath)
【v1.0】单个或多个压缩。
|
static void |
zipOfMultiple(File destFile,
List<File> srcFilesList)
【v1.0】多个文件压缩到一个zip文件。
|
public static void createTextFile(String filePath, String content) throws IOException
filePath - 文件名称(全路径)content - 文件内容。此方法采用utf-8。IOExceptionpublic static void createTextFile(String filePath, String content, String Charset) throws IOException
filePath - 文件名称(全路径)content - 文件内容Charset - 文件编码。如:utf-8/gbk等。IOExceptionpublic static void createFile(String filePath, InputStream inputStream) throws IOException
IOExceptionpublic static void createFile(String filePath, byte[] byteArray) throws IOException
IOExceptionpublic static String readTextFileByUTF8(String fileName) throws Exception
Exceptionpublic static String readTextFile(String filePath, String Charset) throws Exception
filePath - Charset - Exceptionpublic static byte[] readFileBytes(String filePath) throws IOException
filePath - IOExceptionpublic static byte[] readZipFirstFileBytes(String zipFilePath) throws IOException
zipFilePath - IOExceptionpublic static byte[] readZipStreamFirstFileBytes(InputStream zipFile) throws IOException
zipFile - IOExceptionpublic static void createFolder(String folderPath) throws Exception
folderPath - Exceptionpublic static void createFolders(String folderPath) throws Exception
folderPath - 文件夹路径Exceptionpublic static void delFile(String filePath) throws IOException
filePath - 文件路径及名称,如c:/download/abc.txtIOExceptionpublic static void delAllFile(String folderPath) throws IOException
folderPath - 文件夹路径 如 c:/downloadIOExceptionpublic static void delFolder(String folderPath) throws IOException
folderPath - 文件夹路径及名称 如c:/downloadIOExceptionpublic static void copyFile(String oldPath, String newPath) throws IOException
oldPath - 原文件路径,如:c:/abc.DATnewPath - 复制后路径,如:f:/abc.DATIOExceptionpublic static void copyFolder(String oldDirPath, String newDirPath) throws IOException
oldDirPath - 原文件路径,如:c:/abcnewDirPath - 复制后路径,如:f:/aaa/bbbIOExceptionpublic static void moveFile(String oldFilePath, String newFilePath) throws IOException
oldFilePath - 如:c:/abc.DATnewFilePath - 如:d:/abc.DATIOExceptionpublic static void moveFolder(String oldPath, String newPath) throws IOException
oldPath - 如:c:/abcnewPath - 如:d:/abcIOExceptionpublic static void moveAndZipFileToDir(File srcFile, String bakupDir) throws Exception
srcFile - 一个源文件bakupDir - 备份目录Exceptionpublic static void moveAndZipFileToDir(File srcFile, String bakupDir, Boolean isExtentionLowerCase) throws Exception
srcFile - 源文件bakupDir - 备份目录isExtentionLowerCase - 扩展名的zip是否小写。true时,是zip; fales时,是ZIP。主要是针对在线监测的谱图文件扩展名大写才好处理,所以留的此参数。Exceptionpublic static String getSystemProperties(String propertyKey) throws IOException
propertyKey - IOExceptionpublic static String getSystemProperties(String propertyKey, boolean isFromCache) throws IOException
propertyKey - key名称isFromCache - true-程序启动后,第一次读取后存入内存,以后每次从内存取值。false-每次取key时,都重新读取文件,从文件取值。性能要求高时考虑为true。IOExceptionpublic static String getClassLoaderPath()
public static Properties getSystemPropertiesFile() throws IOException
IOExceptionpublic static void propFileSave(Properties properties) throws IOException
IOExceptionpublic static String getFileName(String fullFileName)
fullFileName - 完整路径(含文件名)public static void zipOfMultiple(File destFile, List<File> srcFilesList) throws Exception
destFile - 目标zip文件srcFilesList - 待压缩的原文件的集合Exceptionpublic static void zip(String destFilePath, String srcFilesPath) throws Exception
destFilePath - 目标zip文件srcFilesPath - 待压缩的原文件。如果srcFiles是一个目录,把整个目录压缩到一个zip文件。如果srcFiles是一个文件,则仅压缩这个文件到一个zip文件。Exceptionpublic static void zip(File destFile, File srcFile) throws Exception
destFile - 目标zip文件srcFile - 待压缩的原文件。如果srcFiles是一个目录,把整个目录压缩到一个zip文件。如果srcFiles是一个文件,则仅压缩这个文件到一个zip文件。Exceptionpublic static void unZipToFolder(String zipFilePath, String outputFolderPath) throws IOException
zipFilePath - zip文件全路径outputFolderPath - 解压到的文件夹IOExceptionCopyright © 2024. All rights reserved.