|
@@ -1,65 +0,0 @@
|
|
-package cn.com.qmth.examcloud.core.examwork.base.util;
|
|
|
|
-
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.FileOutputStream;
|
|
|
|
-import java.io.OutputStream;
|
|
|
|
-
|
|
|
|
-import org.apache.commons.io.IOUtils;
|
|
|
|
-import org.slf4j.Logger;
|
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
|
-
|
|
|
|
-import cn.com.qmth.examcloud.commons.base.exception.ExamCloudRuntimeException;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * Created by songyue on 17/7/14.
|
|
|
|
- */
|
|
|
|
-public final class ImportUtils {
|
|
|
|
-
|
|
|
|
- protected static final Logger logger = LoggerFactory.getLogger(ImportUtils.class);
|
|
|
|
-
|
|
|
|
- public static final String TEMP_FILE_IMP = "fileImport/";
|
|
|
|
-
|
|
|
|
- public static final String TEMP_FILE_EXP = "fileExport/";
|
|
|
|
-
|
|
|
|
- static {
|
|
|
|
- init();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 初始化文件夹
|
|
|
|
- */
|
|
|
|
- public static void init() {
|
|
|
|
- File temp_file_exp = new File(TEMP_FILE_EXP);
|
|
|
|
- File temp_file_imp = new File(TEMP_FILE_IMP);
|
|
|
|
- // 如果输出目标文件夹不存在,则创建
|
|
|
|
- if (!temp_file_imp.exists()) {
|
|
|
|
- temp_file_imp.mkdirs();
|
|
|
|
- }
|
|
|
|
- if (!temp_file_exp.exists()) {
|
|
|
|
- temp_file_exp.mkdirs();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取上传文件
|
|
|
|
- *
|
|
|
|
- * @param file
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public static File getUploadFile(MultipartFile file) {
|
|
|
|
- String fileName = file.getOriginalFilename();
|
|
|
|
- File tempFile = new File(TEMP_FILE_IMP + fileName);
|
|
|
|
- OutputStream os = null;
|
|
|
|
- try {
|
|
|
|
- os = new FileOutputStream(tempFile);
|
|
|
|
- IOUtils.copyLarge(file.getInputStream(), os);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- throw new ExamCloudRuntimeException(e);
|
|
|
|
- } finally {
|
|
|
|
- IOUtils.closeQuietly(os);
|
|
|
|
- }
|
|
|
|
- return tempFile;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|