如何从系统配置文件中提取指定键对应的值?
- 内容介绍
- 文章标签
- 相关推荐
本文共计136个文字,预计阅读时间需要1分钟。
javapackage com.cstor.ctape.tools;
import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.util.Properties;
public class ConfigureFileParse { // ...}
package com.cstor.ctape.tools; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class ConfigureFileParse { /** * 根据键读取系统配置文件中对于的值 * @param key * @return String * @throws */ public static String readValue(String key) { String filePath = Constant.ConfigureFilePath; Properties props = new Properties(); InputStream in = null; String value = null; try { in = new BufferedInputStream(new FileInputStream(filePath)); props.load(in); value = props.getProperty(key); } catch (Exception e) { } finally { try { if (in != null) { in.close(); } } catch (IOException e1) { } } return value; } }
本文共计136个文字,预计阅读时间需要1分钟。
javapackage com.cstor.ctape.tools;
import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.util.Properties;
public class ConfigureFileParse { // ...}
package com.cstor.ctape.tools; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class ConfigureFileParse { /** * 根据键读取系统配置文件中对于的值 * @param key * @return String * @throws */ public static String readValue(String key) { String filePath = Constant.ConfigureFilePath; Properties props = new Properties(); InputStream in = null; String value = null; try { in = new BufferedInputStream(new FileInputStream(filePath)); props.load(in); value = props.getProperty(key); } catch (Exception e) { } finally { try { if (in != null) { in.close(); } } catch (IOException e1) { } } return value; } }

