Here you can find the source of getPropertiesVaule(File file, String key, Charset charset)
Parameter | Description |
---|---|
file | the file |
key | the key |
charset | the charset |
Parameter | Description |
---|---|
IOException | the io exception |
public static String getPropertiesVaule(File file, String key, Charset charset) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; import java.nio.charset.Charset; import java.util.Properties; public class Main { /**//from w w w. j av a 2 s. c o m * Gets properties vaule. * * @param file the file * @param key the key * @param charset the charset * @return String properties vaule * @throws IOException the io exception * @Title: getPropertiesVaule * @Description: */ public static String getPropertiesVaule(File file, String key, Charset charset) throws IOException { if (file == null) { return null; } if (charset == null) { charset = Charset.forName("ISO8859-1"); } Properties properties = new Properties(); FileInputStream fis = null; try { fis = new FileInputStream(file); properties.load(fis); } catch (IOException e) { throw new IOException(e); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { throw new IOException(e); } finally { if (properties != null) { properties.clear(); } } } } String value = properties.getProperty(new String(key.getBytes(charset), "ISO8859-1")); if (properties != null) { properties.clear(); } return value == null ? null : new String(value.getBytes("ISO8859-1"), charset); } /** * Gets properties vaule. * * @param file the file * @param key the key * @return String properties vaule * @throws IOException the io exception * @Title: getPropertiesVaule * @Description: */ public static String getPropertiesVaule(File file, String key) throws IOException { return getPropertiesVaule(file, key, null); } }