本文整理了Java中java.util.Properties.load()
方法的一些代码示例,展示了Properties.load()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Properties.load()
方法的具体详情如下:
包路径:java.util.Properties
类名称:Properties
方法名:load
[英]Loads properties from the specified InputStream, assumed to be ISO-8859-1. See "Character Encoding".
[中]从指定的InputStream加载属性,假定为ISO-8859-1。请参阅“{$0$}”。
代码示例来源:origin: square/okhttp
private static String versionString() {
try {
Properties prop = new Properties();
InputStream in = Main.class.getResourceAsStream("/okcurl-version.properties");
prop.load(in);
in.close();
return prop.getProperty("version");
} catch (IOException e) {
throw new AssertionError("Could not load okcurl-version.properties.");
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Properties convert(String source) {
try {
Properties props = new Properties();
// Must use the ISO-8859-1 encoding because Properties.load(stream) expects it.
props.load(new ByteArrayInputStream(source.getBytes(StandardCharsets.ISO_8859_1)));
return props;
}
catch (Exception ex) {
// Should never happen.
throw new IllegalArgumentException("Failed to parse [" + source + "] into Properties", ex);
}
}
代码示例来源:origin: stackoverflow.com
Properties properties = new Properties();
try {
properties.load(new FileInputStream("path/filename"));
} catch (IOException e) {
...
}
代码示例来源:origin: apache/incubator-dubbo
public static Map<String, String> parseProperties(String content) throws IOException {
Map<String, String> map = new HashMap<>();
if (StringUtils.isEmpty(content)) {
logger.warn("You specified the config centre, but there's not even one single config item in it.");
} else {
Properties properties = new Properties();
properties.load(new StringReader(content));
properties.stringPropertyNames().forEach(
k -> map.put(k, properties.getProperty(k))
);
}
return map;
}
代码示例来源:origin: apache/incubator-dubbo
private void loadProperties() {
if (file != null && file.exists()) {
InputStream in = null;
try {
in = new FileInputStream(file);
properties.load(in);
if (logger.isInfoEnabled()) {
logger.info("Load registry cache file " + file + ", data: " + properties);
}
} catch (Throwable e) {
logger.warn("Failed to load registry cache file " + file, e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
logger.warn(e.getMessage(), e);
}
}
}
}
}
代码示例来源:origin: alibaba/jvm-sandbox
private static Properties fetchProperties(final String propertiesFilePath) {
final Properties properties = new Properties();
InputStream is = null;
try {
is = FileUtils.openInputStream(new File(propertiesFilePath));
properties.load(is);
} catch (Throwable cause) {
// cause.printStackTrace(System.err);
} finally {
IOUtils.closeQuietly(is);
}
return properties;
}
代码示例来源:origin: stackoverflow.com
Properties prop = new Properties();
InputStream in = getClass().getResourceAsStream("foo.properties");
prop.load(in);
in.close();
代码示例来源:origin: apache/incubator-dubbo
void loadProperties() {
if (file != null && file.exists()) {
try (InputStream in = new FileInputStream(file)) {
properties.load(in);
if (logger.isInfoEnabled()) {
logger.info("Load service store file " + file + ", data: " + properties);
}
} catch (Throwable e) {
logger.warn("Failed to load service store file " + file, e);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
Properties props = new Properties();
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
props.load(is);
is.close();
代码示例来源:origin: neo4j/neo4j
private static void loadPersistedSettings( Properties settings, PartitionedIndexStorage indexStorage, FileSystemAbstraction fs )
{
File settingsFile = new File( indexStorage.getIndexFolder(), INDEX_CONFIG_FILE );
if ( fs.fileExists( settingsFile ) )
{
try ( Reader reader = fs.openAsReader( settingsFile, StandardCharsets.UTF_8 ) )
{
settings.load( reader );
}
catch ( IOException e )
{
throw new UncheckedIOException( "Failed to read persisted fulltext index properties: " + settingsFile, e );
}
}
}
代码示例来源:origin: ffay/lanproxy
private void initConfig(String configFile) {
InputStream is = Config.class.getClassLoader().getResourceAsStream(configFile);
try {
configuration.load(is);
is.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Fill the given properties from the given resource (in ISO-8859-1 encoding).
* @param props the Properties instance to fill
* @param resource the resource to load from
* @throws IOException if loading failed
*/
public static void fillProperties(Properties props, Resource resource) throws IOException {
InputStream is = resource.getInputStream();
try {
String filename = resource.getFilename();
if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) {
props.loadFromXML(is);
}
else {
props.load(is);
}
}
finally {
is.close();
}
}
代码示例来源:origin: libgdx/libgdx
private static Properties readPropertiesFromFile (File propertiesFile) throws IOException {
InputStream stream = null;
try {
stream = new FileInputStream(propertiesFile);
Properties properties = new Properties();
properties.load(stream);
return properties;
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
代码示例来源:origin: prestodb/presto
public static Map<String, String> loadProperties(File file)
throws IOException
{
Properties properties = new Properties();
try (InputStream in = new FileInputStream(file)) {
properties.load(in);
}
return fromProperties(properties);
}
}
代码示例来源:origin: apache/incubator-dubbo
public static Map<String, String> parseProperties(String content) throws IOException {
Map<String, String> map = new HashMap<>();
if (StringUtils.isEmpty(content)) {
logger.warn("You specified the config centre, but there's not even one single config item in it.");
} else {
Properties properties = new Properties();
properties.load(new StringReader(content));
properties.stringPropertyNames().forEach(
k -> map.put(k, properties.getProperty(k))
);
}
return map;
}
代码示例来源:origin: apache/incubator-dubbo
private void loadProperties() {
if (file != null && file.exists()) {
InputStream in = null;
try {
in = new FileInputStream(file);
properties.load(in);
if (logger.isInfoEnabled()) {
logger.info("Load registry cache file " + file + ", data: " + properties);
}
} catch (Throwable e) {
logger.warn("Failed to load registry cache file " + file, e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
logger.warn(e.getMessage(), e);
}
}
}
}
}
代码示例来源:origin: checkstyle/checkstyle
@Test
public void testClearCache() throws Exception {
final DefaultConfiguration violationCheck =
createModuleConfig(DummyFileSetViolationCheck.class);
final DefaultConfiguration checkerConfig = new DefaultConfiguration("myConfig");
checkerConfig.addAttribute("charset", "UTF-8");
final File cacheFile = temporaryFolder.newFile();
checkerConfig.addAttribute("cacheFile", cacheFile.getPath());
checkerConfig.addChild(violationCheck);
final Checker checker = new Checker();
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.configure(checkerConfig);
checker.addListener(getBriefUtLogger());
checker.process(Collections.singletonList(new File("dummy.java")));
checker.clearCache();
// invoke destroy to persist cache
final PropertyCacheFile cache = Whitebox.getInternalState(checker, "cacheFile");
cache.persist();
final Properties cacheAfterClear = new Properties();
cacheAfterClear.load(Files.newBufferedReader(cacheFile.toPath()));
assertEquals("Cache has unexpected size",
1, cacheAfterClear.size());
}
代码示例来源:origin: stackoverflow.com
static {
Properties prop = new Properties();
InputStream in = CurrentClassName.class.getResourceAsStream("foo.properties");
prop.load(in);
in.close()
}
代码示例来源:origin: apache/incubator-dubbo
void loadProperties() {
if (file != null && file.exists()) {
try (InputStream in = new FileInputStream(file)) {
properties.load(in);
if (logger.isInfoEnabled()) {
logger.info("Load service store file " + file + ", data: " + properties);
}
} catch (Throwable e) {
logger.warn("Failed to load service store file " + file, e);
}
}
}
代码示例来源:origin: stackoverflow.com
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream input = classLoader.getResourceAsStream("foo.properties");
// ...
Properties properties = new Properties();
properties.load(input);
内容来源于网络,如有侵权,请联系作者删除!