Use Relative path in place of absolute path

本秂侑毒 提交于 2019-12-13 04:59:21

问题


First of all i request people do not consider it as a duplicate question, please look into query. I am copying the xml files from one folder to other folder, in the source folder, i have some files which have some content like "backingFile="$IDP_ROOT/metadata/iPAU-SP-metadata.xml" but while writing to the destination folder. i am replacing the "$IDP_ROOT" with my current working directory. The entire copying of files is for deploying into tomcat server. The copying is done only when server starts for the first time. Problem: If i change the folder name from my root path in my machine after i run the server, the entire process will be stopped because the destination folder files already contains the content which is with existed files names or folder names.

So i want to change it to relative path instead absolute path. What is the best way to do it?

Please look at code below:

        // Getting the current working directory
        String currentdir = new File(".").getAbsoluteFile().getParent() + File.separator;

if(currentdir.indexOf("ControlPanel")!=-1){
    rootPath=currentdir.substring(0, currentdir.indexOf("ControlPanel"));
}else{
    rootPath=currentdir;            
}

rootPath = rootPath.replace("\\", "/"); 



        // target file in source folder is having "backingFile="$IDP_ROOT/metadata/iPAU-SP-metadata.xml"

String content = FileReaderUtil.readFile(targetFile,
        rootPath + "Idp/conf");
content = updatePath(content, Install.rootPath
        + "IdP/IdPserver/metadata","$IDP_ROOT");
FileWriterUtil.writeToFile(Install.rootPath
        + "IdP/IdPserver/idp/conf", content,
        targetFile);

    //  update method
   public String updatePath(String content, String replaceString,String replaceKey) {
replaceKey = replaceKey!=null ? replaceKey : "$IDP_SERVER_ROOT";
replaceString= replaceString.replace("\\","/");
String updateContent = content.replace(replaceKey,
        replaceString);
return updateContent;

}

来源:https://stackoverflow.com/questions/26777338/use-relative-path-in-place-of-absolute-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!