private void initFiles() throws IOException {
String path = Main.class.getProtectionDomain().getCodeSource()
.getLocation().getPath();
String decodedPath = URLDecoder.decode(path, "UTF-8");
File clientConfig = new File(decodedPath + "clientConfig.cfg");
boolean existed = true;
if (!clientConfig.exists()) {
clientConfig.createNewFile();
existed = false;
}
BufferedWriter cfgWriter = new BufferedWriter(new FileWriter(
clientConfig));
if (!existed) {
cfgWriter.write("127.0.0.1:10008");
cfgWriter.flush();
}
BufferedReader cfgReader = new BufferedReader(new FileReader(
clientConfig));
String serverInfo[] = cfgReader.readLine().split(":");
host = serverInfo[0];
port = Integer.parseInt(serverInfo[1]);
cfgReader.close();
cfgWriter.close();
}
I believe that the title should be self explanatory, when I execute the jar without the clientConfig.cfg
it works fine, but when it exists already its contents are reset and that causes the rest of the code to stop working