Posted August 27, 201312 yr Hello, I'm trying to edit the configuration of another mod using FileReader/FileWriter in Java. My problem is that it only add the line i've edited, the other text in the configuration is gone. Can someone help me? private class CheckDynamicsConfig extends Thread { @Override public void run() { try { BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\abt\\Desktop\\forge804\\mcp\\jars\\config\\DynamicLights_thePlayer.cfg")); String line = null; while ((line = in.readLine()) != null) { if (line.contains("S:LightItems")) { if (!line.contains("4020")) { BufferedWriter out = new BufferedWriter(new FileWriter("C:\\Users\\abt\\Desktop\\forge804\\mcp\\jars\\config\\DynamicLights_thePlayer.cfg")); String id = ",4020=10"; out.write(line+id); out.close(); } } } in.close(); } catch (IOException e) { e.printStackTrace(); } } }
August 27, 201312 yr FileWriter has a constructor with a boolean to disable overwriting the entire file.
August 28, 201312 yr Author FileWriter has a constructor with a boolean to disable overwriting the entire file. When I set the boolean to true, it adds the line at the end of the file. So i've the files twice and in the configuration it isn't among general { ... } . Is there a way to override only the line and set it to the position? I hope you undertand me.
August 28, 201312 yr Author Use the MinecraftForge Configuration class. You can pass it any file. Don't reinvent the wheel. But i would like to edit the configuration of another mod, not mine. Anyway, solved it using a tmp-file.
August 28, 201312 yr Author There is one problem left. This mod should work universal. When i put in the path the full path with C:\Users... it works, but how can i make it universal like \config\bla.cfg. This can't work because the jar is in the folder versions. Maybe someone can help me
August 28, 201312 yr Author And how I use it to locate the path. Sorry, but I don't understand how to use this method.
August 29, 201312 yr Author I didn't use the FileWrite/Read methods ever in Java, so i didn't learned it But thank you very much!
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.