Java FileReader Read All readAllKeys(String propertyFileName, String xmlFileName)

Here you can find the source of readAllKeys(String propertyFileName, String xmlFileName)

Description

read all the keys from the given property files

License

Open Source License

Parameter

Parameter Description
propertyFileName a parameter
xmlFileName a parameter

Exception

Parameter Description
IOException an exception

Declaration

private static void readAllKeys(String propertyFileName, String xmlFileName) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.FileInputStream;

import java.io.FileReader;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Set;

public class Main {
    /**//from ww w.  jav a  2 s.c  o  m
     * read all the keys from the given property files
     * @param propertyFileName
     * @param xmlFileName
     * @throws IOException 
     */
    private static void readAllKeys(String propertyFileName, String xmlFileName) throws IOException {
        System.out.println("Start of readAllKeys");
        Properties prop = new Properties();
        FileReader reader = new FileReader(propertyFileName);
        prop.load(reader);
        Set<Object> keys = prop.keySet();
        for (Object obj : keys) {
            System.out.println(
                    propertyFileName + ":: Key=" + obj.toString() + "::value=" + prop.getProperty(obj.toString()));
        }
        //loading xml file now, first clear existing properties
        prop.clear();
        InputStream is = new FileInputStream(xmlFileName);
        prop.loadFromXML(is);
        keys = prop.keySet();
        for (Object obj : keys) {
            System.out.println(
                    xmlFileName + ":: Key=" + obj.toString() + "::value=" + prop.getProperty(obj.toString()));
        }
        //Now free all the resources
        is.close();
        reader.close();
        System.out.println("End of readAllKeys");
    }
}

Related

  1. readAll(File file)
  2. readAll(String path)
  3. readAllLines(String filePath)