title: Cheking uniqueness of key values in java properties files
body: <p>I want to load a certain number of properties files into the same java.util.Properties object. I achieve this correctly with the following code:</p>
  
  <pre><code>public class GloalPropReader {
  
  public static final Properties DISPATCHER = new Properties();
  public static final Properties GLOBAL_PROP = new Properties();
  
  public GloalPropReader() {
      try (InputStream input = GloalPropReader.class.getClassLoader().getResourceAsStream("dispatcher.properties")) {
          DISPATCHER.load(input);
      } catch (IOException ex) {
          throw new RuntimeException("Can't access dispatcher information");
      }
  
      for (Object nth : DISPATCHER.keySet()) {
          String nthKey = (String) nth;
          String nthPathToOtherProps = (String) DISPATCHER.get(nthKey);
          Path p = Paths.get(nthPathToOtherProps);
          try (InputStream input = new FileInputStream(p.toFile())) {
              GLOBAL_PROP.load(input);
          } catch (IOException ex) {
              throw new RuntimeException("Can't access " + nthPathToOtherProps + " information");
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And having this properties files:</p>
  
  <p><strong>dispatcher.properties</strong></p>
  
  <pre><code>path_to_prop_1=C:/Users/U/Desktop/k.properties
  path_to_prop_2=C:/Users/U/Desktop/y.properties
  </code></pre>
  
  <p><strong>k.properties</strong></p>
  
  <pre><code>prop1=BLABLA
  </code></pre>
  
  <p><strong>y.properties</strong></p>
  
  <pre><code>prop2=BLEBLE
  </code></pre>
  
  <p>But what i would like to achieve is to throw a RuntimeException if 2 properties file have the same key inside. For instance, <strong>i would like this class to throw an exception if k.properties and y.properties were so</strong>:</p>
  
  <p><strong>k.properties</strong></p>
  
  <pre><code>prop1=BLABLA
  </code></pre>
  
  <p><strong>y.properties</strong></p>
  
  <pre><code>prop1=BLEBLE
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>It's the same as this post <a href="https://stackoverflow.com/questions/10181239/loading-multiple-properties-files">Loading multiple properties files</a> but i don't want the overriding logic when 2 keys are equal</p>