Java Code Examples for com.ruoyi.common.utils.file.FileUtils#deleteFile()

The following examples show how to use com.ruoyi.common.utils.file.FileUtils#deleteFile() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ruoyiplus   File: CommonController.java    License: MIT License 6 votes vote down vote up
/**
 * 通用下载请求
 * 
 * @param fileName 文件名称
 * @param delete 是否删除
 */
@GetMapping("common/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
{
    String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
    try
    {
        String filePath = Global.getDownloadPath() + fileName;

        response.setCharacterEncoding("utf-8");
        response.setContentType("multipart/form-data");
        response.setHeader("Content-Disposition",
                "attachment;fileName=" + setFileDownloadHeader(request, realFileName));
        FileUtils.writeBytes(filePath, response.getOutputStream());
        if (delete)
        {
            FileUtils.deleteFile(filePath);
        }
    }
    catch (Exception e)
    {
        log.error("下载文件失败", e);
    }
}
 
Example 2
Source Project: RuoYi   File: CommonController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping("common/download")
@ApiOperation(value = "通用下载文件")
@ApiImplicitParams({
        @ApiImplicitParam(name = "fileName",value = "文件名",required = true),
        @ApiImplicitParam(name = "delete",value = "是否删除临时文件",required = true,dataType ="boolean")
})
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
    String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf('_') + 1);
    try {
        if (!FileUtils.isValidFilename(fileName)){
            throw new BusinessException(String.format(" 文件名称(%s)非法,不允许下载。 ", fileName));
        }
        String filePath = Global.getDownloadPath() + fileName;

        response.setCharacterEncoding(CharsetKit.UTF8);
        response.setContentType("multipart/form-data");
        response.setHeader("Content-Disposition", "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
        FileUtils.writeBytes(filePath, response.getOutputStream());
        if (delete) {
            FileUtils.deleteFile(filePath);
        }
    } catch (Exception e) {
        log.error("下载文件失败", e);
    }
}
 
Example 3
Source Project: supplierShop   File: CommonController.java    License: MIT License 5 votes vote down vote up
/**
 * 通用下载请求
 * 
 * @param fileName 文件名称
 * @param delete 是否删除
 */
@GetMapping("common/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
{
    try
    {
        if (!FileUtils.isValidFilename(fileName))
        {
            throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
        }
        String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
        String filePath = Global.getDownloadPath() + fileName;

        response.setCharacterEncoding("utf-8");
        response.setContentType("multipart/form-data");
        response.setHeader("Content-Disposition",
                "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
        FileUtils.writeBytes(filePath, response.getOutputStream());
        if (delete)
        {
            FileUtils.deleteFile(filePath);
        }
    }
    catch (Exception e)
    {
        log.error("下载文件失败", e);
    }
}
 
Example 4
Source Project: RuoYi-Vue   File: CommonController.java    License: MIT License 5 votes vote down vote up
/**
 * 通用下载请求
 * 
 * @param fileName 文件名称
 * @param delete 是否删除
 */
@GetMapping("common/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
{
    try
    {
        if (!FileUtils.isValidFilename(fileName))
        {
            throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
        }
        String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
        String filePath = RuoYiConfig.getDownloadPath() + fileName;

        response.setCharacterEncoding("utf-8");
        response.setContentType("multipart/form-data");
        response.setHeader("Content-Disposition",
                "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
        FileUtils.writeBytes(filePath, response.getOutputStream());
        if (delete)
        {
            FileUtils.deleteFile(filePath);
        }
    }
    catch (Exception e)
    {
        log.error("下载文件失败", e);
    }
}