Java Folder Read getFileSystemProperty(String name)

Here you can find the source of getFileSystemProperty(String name)

Description

get File System Property

License

Apache License

Declaration

public static File getFileSystemProperty(String name) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private static final Pattern VAR_PTN = Pattern.compile("\\$\\{([^\\}]+)\\}");

    public static File getFileSystemProperty(String name) {
        return getFileSystemProperty(name, null);
    }/*  ww  w.j  a  v a  2s.  c  o m*/

    public static File getFileSystemProperty(String name, File defaultFile) {
        String fileStr = replace(System.getProperty(name));
        if (fileStr != null)
            return new File(fileStr);
        else
            return defaultFile;
    }

    private static String replace(String value) {
        if (value == null)
            return null;
        StringBuffer sb = new StringBuffer(256);
        Matcher m = VAR_PTN.matcher(value);
        while (m.find()) {
            String propValue = System.getProperty(m.group(1));
            if (propValue == null)
                propValue = "";
            m.appendReplacement(sb, Matcher.quoteReplacement(propValue));
        }
        m.appendTail(sb);
        return sb.toString();
    }
}

Related

  1. getFileString(File file)
  2. getFileString(String filePath)
  3. getFileStringContent(String filename)
  4. GetFilesWithChildren(File root, ArrayList files)
  5. getFileSystemProperties(String path)