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

The following examples show how to use cn.hutool.core.io.FileUtil#getAbsolutePath() . 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: StringUtil.java    From Jpom with MIT License 6 votes vote down vote up
/**
 * 删除文件开始的路径
 *
 * @param file      要删除的文件
 * @param startPath 开始的路径
 * @param inName    是否返回文件名
 * @return /test/a.txt /test/  a.txt
 */
public static String delStartPath(File file, String startPath, boolean inName) {
    String newWhitePath;
    if (inName) {
        newWhitePath = FileUtil.getAbsolutePath(file.getAbsolutePath());
    } else {
        newWhitePath = FileUtil.getAbsolutePath(file.getParentFile());
    }
    String itemAbsPath = FileUtil.getAbsolutePath(new File(startPath));
    itemAbsPath = FileUtil.normalize(itemAbsPath);
    newWhitePath = FileUtil.normalize(newWhitePath);
    String path = newWhitePath.substring(newWhitePath.indexOf(itemAbsPath) + itemAbsPath.length());
    path = FileUtil.normalize(path);
    if (path.startsWith(StrUtil.SLASH)) {
        path = path.substring(1);
    }
    return path;
}
 
Example 2
Source File: ScriptProcessBuilder.java    From Jpom with MIT License 5 votes vote down vote up
private ScriptProcessBuilder(ScriptModel scriptModel, String args) {
    this.logFile = scriptModel.logFile();
    this.scriptFile = scriptModel.getFile(true);
    //
    String script = FileUtil.getAbsolutePath(scriptFile);
    processBuilder = new ProcessBuilder();
    List<String> command = StrUtil.splitTrim(args, StrUtil.SPACE);
    command.add(0, script);
    if (SystemUtil.getOsInfo().isLinux()) {
        command.add(0, CommandUtil.SUFFIX);
    }
    DefaultSystemLog.getLog().info(CollUtil.join(command, StrUtil.SPACE));
    processBuilder.command(command);
}
 
Example 3
Source File: FileUtils.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 获取java 文件路径
 *
 * @param path path
 * @param w    是否使用javaw
 * @return 完整路径
 */
public static String getJdkJavaPath(String path, boolean w) {
    String fileName;
    if (SystemUtil.getOsInfo().isWindows()) {
        fileName = w ? "javaw.exe" : "java.exe";
    } else {
        fileName = w ? "javaw" : "java";
    }
    File newPath = FileUtil.file(path, "bin", fileName);
    return FileUtil.getAbsolutePath(newPath);
}
 
Example 4
Source File: ProjectFileControl.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 文件管理页面
 *
 * @param id 项目id
 * @return page
 */
@RequestMapping(value = "list.html", method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
@Feature(method = MethodFeature.FILE)
public String fileManage(String id) {
    setAttribute("id", id);
    JSONObject projectInfo = projectInfoService.getItem(getNode(), id);
    String lib = projectInfo.getString("lib");
    String whitelistDirectory = projectInfo.getString("whitelistDirectory");
    lib = FileUtil.getAbsolutePath(FileUtil.file(whitelistDirectory, lib));
    setAttribute("absLib", lib);
    return "node/manage/filemanage";
}
 
Example 5
Source File: UploadServiceImpl.java    From NoteBlog with MIT License 5 votes vote down vote up
private String saveFile(String path, String fileName, TemplateSupplier<byte[]> fileBytes) throws Exception {
    String prefix = environment.getProperty("spring.resources.static-locations");
    String filePath = prefix + path + "/" + fileName;
    filePath = FileUtil.getAbsolutePath(filePath);
    FileOutputStream out = new FileOutputStream(filePath);
    out.write(fileBytes.get());
    out.flush();
    out.close();
    return filePath;
}
 
Example 6
Source File: DbConfig.java    From Jpom with MIT License 4 votes vote down vote up
/**
 * 获取数据库的jdbc 连接
 *
 * @return jdbc
 */
public String getDbUrl() {
    File file = FileUtil.file(ExtConfigBean.getInstance().getAbsolutePath(), DB, JpomApplication.getAppType().name());
    String path = FileUtil.getAbsolutePath(file);
    return StrUtil.format("jdbc:h2:{}", path);
}
 
Example 7
Source File: ExtConfigBean.java    From Jpom with MIT License 4 votes vote down vote up
public String getAbsolutePath() {
    return FileUtil.getAbsolutePath(FileUtil.file(getPath()));
}