Java: Load multiple properties files as one

Noodly_Doodly

Sorry if the title is unclear.

What I'm trying to do is load configuration files "on top of each other".

Say I have Config #1:

config.property=Something Here

And Config #2:

config.otherproperty=Other Thingy Here

And the java app loads it as this:

config.property=Something Here

config.otherproperty=Other Thingy Here

As though it was all one file.

How would I do this?

hfontanez

I am unclear as to what you really need. If I understood you correctly, you want to load two properties file into a single Properties object. If this is the case, the all you have to do is something like this:

PropsDemo demo = new PropsDemo();
String prop1 = "config1.properties";
String prop2 = "config2.properties";

Properties props = new Properties();
InputStream input1 = demo.getClass().getClassLoader().getResourceAsStream(prop1);
InputStream input2 = demo.getClass().getClassLoader().getResourceAsStream(prop2);
try
{
    props.load(input1);
    props.load(input2);
    System.out.println(props.toString());
}
catch (IOException e)
{
    System.out.println("Something went wrong!");
}

The file config1.properties contains:

color=blue

And the file config2.properties contains:

shape=circle

The snippet above outputs:

{shape=circle, color=blue}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Java: Load multiple properties files as one

From Dev

One-liner to load files into java.util.Properties

From Dev

Load multiple resource files into one resource manager

From Dev

Load multiple babylon files in one html

From Dev

Load multiple files into one div via JQuery .load?

From Dev

Load multiple files into one div via JQuery .load?

From Dev

Can luaL_loadbuffer load multiple files in one call?

From Dev

Can luaL_loadbuffer load multiple files in one call?

From Dev

Three.js load Multiple obj files one after another

From Dev

Load multiple files in React-Native in one line

From Dev

Combining multiple text files into one in Java

From Dev

Download multiple files with one progressbar java / Android

From Dev

Load multiple JSON files

From Dev

Load multiple files with Modernizr

From Dev

EWS Managed API: Can I load properties for multiple items with one EWS call, given only the item IDs?

From Dev

Loading multiple properties files with Camel

From Dev

Bind multiple files to array with properties

From Dev

Concatenating multiple files into one

From Dev

One output with multiple files

From Dev

Declaration of multiple properties in one line

From Dev

Declaration of multiple properties in one line

From Dev

How to append text to multiple files in one directory using Java

From Dev

Java load properties file correctly

From Dev

Load files dynamically in multiple environments

From Dev

Load multiple files with PigLatin (Hadoop)

From Dev

How to load multiple files in ssis

From Dev

Load multiple picture files with angularjs

From Dev

Load multiple .csv-files into one table and create ID per .csv -postgres

From Dev

Load Multiple Urls as One Page

Related Related

HotTag

Archive