Example usage for java.util Properties Properties

List of usage examples for java.util Properties Properties

Introduction

In this page you can find the example usage for java.util Properties Properties.

Prototype

public Properties() 

Source Link

Document

Creates an empty property list with no default values.

Usage

From source file:Main.java

public static String getProperty(Context context, String key) {
    try {//from w w w .  j  av  a 2s.c  o  m
        Properties props = new Properties();
        InputStream input = context.getAssets().open("config.properties");
        if (input != null) {
            props.load(input);
            return props.getProperty(key);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static Properties readProperties(InputStream input) {
    Properties properties = new Properties();
    return readProperties(input, properties) ? properties : null;
}

From source file:Main.java

public static void saveAccount(Activity act, String account, String psw) {
    String str = account + "," + psw;
    Properties localProperties = new Properties();
    localProperties.put("account", str);
    try {//from w w  w  . ja va 2 s  .  c  o m
        File file = new File(act.getFilesDir() + "/accout.cfg");
        if (!file.exists())
            file.createNewFile();
        FileOutputStream localFileOutputStream = act.openFileOutput("account.cfg", Context.MODE_PRIVATE);
        localProperties.store(localFileOutputStream, "");
        localFileOutputStream.close();
    } catch (Exception localException) {
        localException.printStackTrace();
    }
}

From source file:Main.java

public static String getCurrentProject() {
    try {/*from www. j  av  a  2 s .  c o  m*/
        String value = "";
        Properties properties = new Properties();
        FileInputStream inputFile = new FileInputStream(System.getProperty("user.dir") + "/system.properties");
        properties.load(inputFile);
        inputFile.close();

        if (properties.containsKey("ProjectPath")) {
            value = properties.getProperty("ProjectPath");
            String resultName = new String(value.getBytes("ISO-8859-1"), "gbk");
            return resultName;
        } else
            return value;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return "";
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    } catch (Exception ex) {
        ex.printStackTrace();
        return "";
    }
}

From source file:Main.java

private static Properties loadPropties(Context context, String file) throws IOException {
    Properties properties = new Properties();
    try {/*from  w w w.j  a v  a 2 s. c  o m*/
        InputStream fileStream = context.getAssets().open(file);
        properties.load(fileStream);
        fileStream.close();
    } catch (FileNotFoundException e) {
    }
    return properties;
}

From source file:Main.java

private static String getVerNameFromAssert(Context context) {

    String versionName = "";
    try {//from  w w  w. j  a va2  s.c o  m
        Properties pro = new Properties();
        InputStream is = context.getAssets().open("channel.properties");
        pro.load(is);
        String tmpVersionName = pro.getProperty("versionName");

        versionName = new String(tmpVersionName.getBytes("ISO-8859-1"), "UTF-8");

        is.close();
        is = null;
    } catch (Exception e) {
        versionName = "";
        Log.e(TAG, "AppConfig.loadVersion have Exception e = " + e.getMessage());
    }
    return versionName;

}

From source file:Main.java

public static Map<String, String> toMap(String properties) {
    try {/*  w  ww.  jav  a  2  s .co m*/
        InputStream is = new ByteArrayInputStream(properties.getBytes("UTF-8"));
        Properties prop = new Properties();
        prop.load(is);
        Map<String, String> ret = new HashMap<String, String>();
        for (String key : prop.stringPropertyNames()) {
            ret.put(key, prop.getProperty(key));
        }
        return ret;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:Main.java

/**
 * returns a P with the value of the specifed attribute of the specifed tags
 * //from   ww  w . java  2s  . c o m
 * @param doc
 * @param strTagName
 * @param strAttribute
 * @return
 */
public static Properties getPropertiesFromArrayList(ArrayList<String> al) {

    Properties pr = new Properties();

    // cycles on all of them
    for (int i = 0; i < al.size(); i++) {

        pr.setProperty(al.get(i), "");
    }

    return pr;
}

From source file:Main.java

static boolean isTestnet(final Context c) {
    try {/*from w  w w  . ja  v a2 s . c  om*/
        final Properties p = new Properties();
        p.load(new BufferedInputStream(new FileInputStream(getBitcoinConf(c))));
        return p.getProperty("testnet", p.getProperty("regtest", "0")).equals("1");
    } catch (final IOException e) {
        return false;
    }
}

From source file:Main.java

private static Properties importProperties(NodeList nodeList) {
    Properties properties = new Properties();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Element entry = (Element) nodeList.item(i);
        if (entry.hasAttribute("name")) {
            String val = (entry == null) ? "" : entry.getFirstChild().getNodeValue();
            String key = entry.getAttribute("name");
            properties.setProperty(key, val);
        }//from  w  w  w . j  a v a2  s . c o  m
    }
    return properties;
}