Java Code Examples for cn.hutool.core.io.FileUtil#mkdir()

The following examples show how to use cn.hutool.core.io.FileUtil#mkdir() . 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: JpomApplicationEvent.java    From Jpom with MIT License 8 votes vote down vote up
private static void checkPath() {
    String path = ExtConfigBean.getInstance().getPath();
    String extConfigPath = null;
    try {
        extConfigPath = ExtConfigBean.getResource().getURL().toString();
    } catch (IOException ignored) {
    }
    File file = FileUtil.file(path);
    try {
        FileUtil.mkdir(file);
        file = FileUtil.createTempFile("jpom", ".temp", file, true);
    } catch (Exception e) {
        DefaultSystemLog.getLog().error(StrUtil.format("Jpom创建数据目录失败,目录位置:{},请检查当前用户是否有此目录权限或修改配置文件:{}中的jpom.path为可创建目录的路径", path, extConfigPath), e);
        System.exit(-1);
    }
    FileUtil.del(file);
    DefaultSystemLog.getLog().info("Jpom[{}]外部配置文件路径:{}", JpomManifest.getInstance().getVersion(), extConfigPath);
}
 
Example 2
Source File: ExecutorJobHandler.java    From datax-web with MIT License 6 votes vote down vote up
private String generateTemJsonFile(String jobJson) {
    String tmpFilePath;
    String dataXHomePath = SystemUtils.getDataXHomePath();
    if (StringUtils.isNotEmpty(dataXHomePath)) {
        jsonPath = dataXHomePath + DEFAULT_JSON;
    }
    if (!FileUtil.exist(jsonPath)) {
        FileUtil.mkdir(jsonPath);
    }
    tmpFilePath = jsonPath + "jobTmp-" + IdUtil.simpleUUID() + ".conf";
    // 根据json写入到临时本地文件
    try (PrintWriter writer = new PrintWriter(tmpFilePath, "UTF-8")) {
        writer.println(jobJson);
    } catch (FileNotFoundException | UnsupportedEncodingException e) {
        JobLogger.log("JSON 临时文件写入异常:" + e.getMessage());
    }
    return tmpFilePath;
}
 
Example 3
Source File: CompressionFileUtil.java    From Jpom with MIT License 5 votes vote down vote up
private static List<String> unTar(InputStream inputStream, File destDir) throws Exception {
    List<String> fileNames = new ArrayList<>();
    TarArchiveInputStream tarIn = new TarArchiveInputStream(inputStream, BUFFER_SIZE, CharsetUtil.GBK);
    TarArchiveEntry entry;
    try {
        while ((entry = tarIn.getNextTarEntry()) != null) {
            fileNames.add(entry.getName());
            if (entry.isDirectory()) {
                //是目录
                FileUtil.mkdir(new File(destDir, entry.getName()));
                //创建空目录
            } else {
                //是文件
                File tmpFile = new File(destDir, entry.getName());
                //创建输出目录
                FileUtil.mkParentDirs(destDir);
                OutputStream out = null;
                try {
                    out = new FileOutputStream(tmpFile);
                    int length;
                    byte[] b = new byte[2048];
                    while ((length = tarIn.read(b)) != -1) {
                        out.write(b, 0, length);
                    }
                } finally {
                    IOUtils.closeQuietly(out);
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(tarIn);
    }
    return fileNames;
}
 
Example 4
Source File: ServerConfigBean.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 获取当前登录用户的临时文件存储路径,如果没有登录则抛出异常
 *
 * @return file
 */
public File getUserTempPath() {
    File file = getTempPath();
    UserModel userModel = BaseServerController.getUserModel();
    if (userModel == null) {
        throw new JpomRuntimeException("没有登录");
    }
    file = FileUtil.file(file, userModel.getId());
    FileUtil.mkdir(file);
    return file;
}
 
Example 5
Source File: DocumentBrowser.java    From book118-downloader with MIT License 5 votes vote down vote up
void writeTaskList(List<String> pLists) {
    if (!FileUtil.exist(DES_PATH)) {
        FileUtil.mkdir(DES_PATH);
    }
    FileWriter fileWriter = new FileWriter(TASK_LIST_FILE);
    fileWriter.appendLines(pLists);
}
 
Example 6
Source File: DocumentBrowser.java    From book118-downloader with MIT License 5 votes vote down vote up
/**
 *  下载文档的全部图片
 *
 * @param documentId 文档编号
 * @throws IOException       pdf创建错误
 * @throws DocumentException pdf创建错误
 */
void downloadWholeDocument(String documentId) throws IOException, DocumentException {
    String srcPath = TEMP_PATH + "/" + documentId;
    FileUtil.mkdir(new File(srcPath));
    FileUtil.mkdir(new File(DES_PATH));

    int page = 1, nDownloadedPage;
    // 断点下载
    nDownloadedPage = readDownloadedPage(documentId);
    if (nDownloadedPage != 1) {
        System.out.println(String.format("下载继续,当前已完成 %d 页", nDownloadedPage));
        nDownloadedPage ++;
    }
    StringBuilder currentDownPage = new StringBuilder();
    PdfInfo pdfInfo = getPdfInfo(documentId);
    String imgUrl;
    StaticLog.info("\n开始下载...");
    while (pdfInfo != null) {
        String nextPage = moveToNextPage(pdfInfo);
        if (!Constants.TAG_OF_END.contains(nextPage)) {
            //跳过已下载的文件
            if (page < nDownloadedPage) {
                System.out.print(String.format("\r当前页码: [%d]  已跳过", page));
                page ++; continue;
            }
            imgUrl = (pdfInfo.getHost() + Constants.IMG_PREFIX_URL + nextPage);
            downloadFile(imgUrl, srcPath + "/" + autoGenericCode(page, Constants.MAX_BIT_OF_PAGE) + ".gif");
            currentDownPage.append("\r").append(String.format("已下载页数:[%d] 页", page));
            System.out.print(currentDownPage);
            // 保存当前下载完成页码
            writeDownloadedPage(documentId, page);
            page++;
        } else {
            break;
        }
    }
    StaticLog.info("\n开始生成...");
    PdfGenerator.creatPDF(srcPath, DES_PATH + "/" + documentId + ".pdf", "gif");
    FileUtil.del(new File(srcPath));
}
 
Example 7
Source File: ConfigBean.java    From Jpom with MIT License 4 votes vote down vote up
/**
 * 获取项目运行数据存储文件夹路径
 *
 * @return 文件夹路径
 */
public String getDataPath() {
    String dataPath = FileUtil.normalize(ExtConfigBean.getInstance().getPath() + "/" + DATA);
    FileUtil.mkdir(dataPath);
    return dataPath;
}