com.xiaoleilu.hutool.io.FileUtil Java Examples

The following examples show how to use com.xiaoleilu.hutool.io.FileUtil. 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 File: VideoCrontab.java    From roncoo-education with MIT License 5 votes vote down vote up
/**
 * 定时任务每分钟执行一次 <br/>
 * 注意:每个course服务都必须要对应有一个定时任务,针对服务器
 */
@Scheduled(fixedRate = 60000)
public void orderCancel() {
	synchronized (KEY) {
		if (VideoCrontab.taskFlag) {
			logger.warn("视频处理-任务已经启动");
			return;
		}
		VideoCrontab.taskFlag = true;
	}

	int videoSum = 0;

	File file = new File(SystemUtil.PERIOD_VIDEO_PATH);
	if (file.isDirectory()) {// isDirectory是否文件夹
		File[] files = file.listFiles();// listFiles是获取该目录下所有文件和目录的绝对路径
		for (File targetFile : files) {

			if (targetFile.isFile() && targetFile.exists()) {
				if (FileUtil.newerThan(targetFile, (System.currentTimeMillis() - 7200000))) {// 上传两个小时内

					try {
						feignCourseVideo.handleScheduledTasks(targetFile);
						videoSum = videoSum + 1;
					} catch (Exception e) {
						logger.error("视频定时任务处理失败", e);
					}

				}
			}
		}
	}

	VideoCrontab.taskFlag = false;

	logger.warn("视频处理-定时任务完成,处理视频数={}", videoSum);
}
 
Example #2
Source File: UserController.java    From pig with MIT License 5 votes vote down vote up
/**
 * 上传用户头像
 * (多机部署有问题,建议使用独立的文件服务器)
 *
 * @param file 资源
 * @return filename map
 */
@PostMapping("/upload")
public Map<String, String> upload(@RequestParam("file") MultipartFile file) {
    String fileExt = FileUtil.extName(file.getOriginalFilename());
    Map<String, String> resultMap = new HashMap<>(1);
    try {
        StorePath storePath = fastFileStorageClient.uploadFile(file.getBytes(), fileExt);
        resultMap.put("filename", fdfsPropertiesConfig.getFileHost() + storePath.getFullPath());
    } catch (IOException e) {
        logger.error("文件上传异常", e);
        throw new RuntimeException(e);
    }
    return resultMap;
}