Last active
February 22, 2021 10:03
-
-
Save diogoalexsmachado/b5c392e34e8f01079856e739ac41fdde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PropertiesToConstantsGenerator { | |
public static void main(String[] args) throws IOException { | |
Properties properties = new Properties(); | |
InputStream inputStream =PropertiesToInterfaceGenerator.class.getClassLoader().getResourceAsStream("saf_en.properties"); | |
if(null != inputStream ){ | |
properties.load(inputStream); | |
} | |
generate(properties); | |
} | |
public static void generate(Properties properties) { | |
Enumeration e = properties.propertyNames(); | |
try { | |
FileWriter fileWriter = new FileWriter("PropertiesSAFConstants.java", true); | |
fileWriter.write("public interface PropertiesSAFConstants{\n"); | |
while (e.hasMoreElements()) { | |
String key = (String) e.nextElement(); | |
String val = properties.getProperty(key); | |
fileWriter.write("\tpublic static String "+key+" = \""+val+"\";\n"); | |
} | |
fileWriter.write(" }\n"); | |
fileWriter.flush(); | |
fileWriter.close(); | |
}catch(Exception ex){ | |
ex.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment