类 SohelpFileUploadService
java.lang.Object
net.sohelp.boot.admin.core.service.file.SohelpFileUploadService
文件上传操作服务类,提供文件的上传、删除、读取等功能。
- 从以下版本开始:
- 2024/2/28 12:22
- 作者:
- AaronFung
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明void删除指定模块中的某个文件。boolean判断指定模块中的文件是否存在。获取指定模块中某文件的File对象。getFileInfo(String moduleName, String fileName) 获取指定模块中文件的基本信息。getInputStream(String moduleName, String fileName) 获取指定模块中某文件的输入流对象。booleanupload(String moduleName, String fileName, InputStream inputStream) 将输入流保存到指定模块下的文件中。
-
构造器详细资料
-
SohelpFileUploadService
public SohelpFileUploadService()
-
-
方法详细资料
-
upload
@Comment("\u4e0a\u4f20\u6587\u4ef6") public boolean upload(String moduleName, String fileName, InputStream inputStream) throws BusiException 将输入流保存到指定模块下的文件中。- 参数:
moduleName- 模块名称,用于构建存储路径。必须符合正则表达式 ^[a-zA-Z0-9_-]+$fileName- 文件名,必须符合正则表达式 ^[a-zA-Z0-9-_.]+$inputStream- 输入流数据源- 返回:
- 成功时返回true
- 抛出:
BusiException- 当模块名或文件名不符合规范时抛出异常
-
delete
@Comment("\u5220\u9664\u6587\u4ef6") public void delete(String moduleName, String fileName) throws BusiException 删除指定模块中的某个文件。- 参数:
moduleName- 模块名称fileName- 要删除的文件名- 抛出:
BusiException- 若发生IO错误或其他业务逻辑问题将抛出该异常
-
getInputStream
@Comment("\u83b7\u53d6\u6587\u4ef6\u6d41") public InputStream getInputStream(String moduleName, String fileName) throws BusiException 获取指定模块中某文件的输入流对象。- 参数:
moduleName- 模块名称fileName- 文件名- 返回:
- 对应文件的InputStream实例
- 抛出:
BusiException- 若文件不存在或无法访问会抛出异常
-
getFile
@Comment("\u83b7\u53d6\u6587\u4ef6") public File getFile(String moduleName, String fileName) throws BusiException 获取指定模块中某文件的File对象。- 参数:
moduleName- 模块名称fileName- 文件名- 返回:
- 表示对应文件的File对象
- 抛出:
BusiException- 若构造路径失败或模块为空会抛出异常
-
exists
@Comment("\u5224\u65ad\u6587\u4ef6\u662f\u5426\u5b58\u5728") public boolean exists(String moduleName, String fileName) throws BusiException 判断指定模块中的文件是否存在。- 参数:
moduleName- 模块名称fileName- 文件名- 返回:
- 存在返回true,否则false
- 抛出:
BusiException- 若模块名为空则抛出异常
-
getFileInfo
@Comment("\u83b7\u53d6\u6587\u4ef6\u4fe1\u606f") public Map getFileInfo(String moduleName, String fileName) throws BusiException 获取指定模块中文件的基本信息。- 参数:
moduleName- 模块名称fileName- 文件名- 返回:
- 包含文件基本信息的Map集合,包括路径、大小、最后修改时间等字段
- 抛出:
BusiException- 若文件不存在则抛出异常
-