Because it is a configuration file I would recommend you use a file of type .ini
, but unfortunately Java does not have a default library to do this type of operation, if you agree to do so you can download the library from the address : link There is also the option of downloading it directly from Maven.
Downloaded and imported the library, you need to place a section in your file so that it is correctly interpreted with a file of type .ini
. Example:
[cfg]
inPath = C: \ Input; Entry directory
outPath = C: \ Output; Outbound Directory
inProcess = C: \ Under Processing; Processing directory
And the code would look like this:
import java.io.File;
import java.io.IOException;
import org.ini4j.Ini;
import org.ini4j.IniPreferences;
import org.ini4j.InvalidFileFormatException;
public class Teste {
public static void main(String[] args) throws InvalidFileFormatException, IOException {
Ini ini = new Ini(new File("meucfg.ini"));
java.util.prefs.Preferences prefs = new IniPreferences(ini);
String inPath = prefs.node("cfg").get("inPath", "null").split(";")[0].trim();
String outPath = prefs.node("cfg").get("outPath", "null").split(";")[0].trim();
String inProcess = prefs.node("cfg").get("inProcess", "null").split(";")[0].trim();
System.out.printf("inPath: %s\noutPath: %s\ninProcess: %s\n", inPath, outPath, inProcess);
}
}
Output:
inPath: C: \ Input
outPath: C: \ Output
inProcess: C: \ Under Processing