mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-08 13:27:46 +00:00
增加分布式文件FastDFS支持
This commit is contained in:
@@ -20,6 +20,12 @@ import com.ruoyi.common.core.utils.StringUtils;
|
||||
*/
|
||||
public class FileUtils extends org.apache.commons.io.FileUtils
|
||||
{
|
||||
/** 字符常量:斜杠 {@code '/'} */
|
||||
public static final char SLASH = '/';
|
||||
|
||||
/** 字符常量:反斜杠 {@code '\\'} */
|
||||
public static final char BACKSLASH = '\\';
|
||||
|
||||
public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
|
||||
|
||||
/**
|
||||
@@ -167,6 +173,57 @@ public class FileUtils extends org.apache.commons.io.FileUtils
|
||||
return filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回文件名
|
||||
*
|
||||
* @param filePath 文件
|
||||
* @return 文件名
|
||||
*/
|
||||
public static String getName(String filePath)
|
||||
{
|
||||
if (null == filePath)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int len = filePath.length();
|
||||
if (0 == len)
|
||||
{
|
||||
return filePath;
|
||||
}
|
||||
if (isFileSeparator(filePath.charAt(len - 1)))
|
||||
{
|
||||
// 以分隔符结尾的去掉结尾分隔符
|
||||
len--;
|
||||
}
|
||||
|
||||
int begin = 0;
|
||||
char c;
|
||||
for (int i = len - 1; i > -1; i--)
|
||||
{
|
||||
c = filePath.charAt(i);
|
||||
if (isFileSeparator(c))
|
||||
{
|
||||
// 查找最后一个路径分隔符(/或者\)
|
||||
begin = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return filePath.substring(begin, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为Windows或者Linux(Unix)文件分隔符<br>
|
||||
* Windows平台下分隔符为\,Linux(Unix)为/
|
||||
*
|
||||
* @param c 字符
|
||||
* @return 是否为Windows或者Linux(Unix)文件分隔符
|
||||
*/
|
||||
public static boolean isFileSeparator(char c)
|
||||
{
|
||||
return SLASH == c || BACKSLASH == c;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件名重新编码
|
||||
*
|
||||
|
Reference in New Issue
Block a user