public class FileUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static char |
BACKSLASH
字符常量:反斜杠
'\\' |
static String |
FILENAME_PATTERN |
static char |
SLASH
字符常量:斜杠
'/' |
| 构造器和说明 |
|---|
FileUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
checkAllowDownload(String resource)
检查文件是否可下载
|
static boolean |
deleteFile(String filePath)
删除文件
|
static String |
getName(String filePath)
返回文件名
|
static boolean |
isFileSeparator(char c)
是否为Windows或者Linux(Unix)文件分隔符
Windows平台下分隔符为\,Linux(Unix)为/ |
static boolean |
isValidFilename(String filename)
文件名称验证
|
static String |
percentEncode(String s)
百分号编码工具方法
|
static void |
setAttachmentResponseHeader(javax.servlet.http.HttpServletResponse response,
String realFileName)
下载文件名重新编码
|
static String |
setFileDownloadHeader(javax.servlet.http.HttpServletRequest request,
String fileName)
下载文件名重新编码
|
static void |
writeBytes(String filePath,
OutputStream os)
输出指定文件的byte数组
|
public static final char SLASH
'/'public static final char BACKSLASH
'\\'public static String FILENAME_PATTERN
public static void writeBytes(String filePath, OutputStream os) throws IOException
filePath - 文件路径os - 输出流IOExceptionpublic static boolean deleteFile(String filePath)
filePath - 文件public static boolean isValidFilename(String filename)
filename - 文件名称public static boolean checkAllowDownload(String resource)
resource - 需要下载的文件public static String setFileDownloadHeader(javax.servlet.http.HttpServletRequest request, String fileName) throws UnsupportedEncodingException
request - 请求对象fileName - 文件名UnsupportedEncodingExceptionpublic static boolean isFileSeparator(char c)
c - 字符public static void setAttachmentResponseHeader(javax.servlet.http.HttpServletResponse response,
String realFileName)
throws UnsupportedEncodingException
response - 响应对象realFileName - 真实文件名UnsupportedEncodingExceptionpublic static String percentEncode(String s) throws UnsupportedEncodingException
s - 需要百分号编码的字符串UnsupportedEncodingExceptionCopyright © 2021. All rights reserved.