Skip to content

Instantly share code, notes, and snippets.

@diogoalexsmachado
Last active February 22, 2021 10:03
Show Gist options
  • Save diogoalexsmachado/b5c392e34e8f01079856e739ac41fdde to your computer and use it in GitHub Desktop.
Save diogoalexsmachado/b5c392e34e8f01079856e739ac41fdde to your computer and use it in GitHub Desktop.
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