如何获取键读取系统配置文件中的特定值?
- 内容介绍
- 文章标签
- 相关推荐
本文共计142个文字,预计阅读时间需要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 { /* 解析配置文件 */}
ConfigureFileParse.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 { /** * 根据键读取系统配置文件中对于的值 * @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; } }
本文共计142个文字,预计阅读时间需要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 { /* 解析配置文件 */}
ConfigureFileParse.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 { /** * 根据键读取系统配置文件中对于的值 * @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; } }

