Hack Forums
[Java] Simple config loading [SRC] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Simple config loading [SRC] (/showthread.php?tid=5347287)



Simple config loading [SRC] - charmeur - Jul 22, 2016

use JSON configs, which is faster&simpler.

Config file structure: PROPERTYSTRING1=str

PROPERTYSTRING2=str2

PHP Code

<?php 
public static void loadConfig() {
        
Properties prop = new Properties();
        
InputStream input = null;
 
        try {
            
input = new FileInputStream("config.txt");
            
prop.load(input);
 
            
String s = prop.getProperty("PROPERTY_STRING_1");
        } catch (
IOException ex) {
            
ex.printStackTrace();
        } finally {
            if (
input != null) {
                try {
                    
input.close();
                } catch (
IOException e) {
                    
e.printStackTrace();
                }
            }
        }
    } 

Enjoy πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰


* - Stealthβ„’ - Jul 23, 2016

This code is outdated, as you should be using a try-with-resources statement so you don't have to worry about closing the stream.

Also you noted to use JSON configs but provided code for a text file. What was the point?

You should really explain to everyone about what your code does instead of just blindly posting it.