Zcelo12 Posted August 27, 2013 Posted August 27, 2013 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(); } } } Quote
GotoLink Posted August 27, 2013 Posted August 27, 2013 FileWriter has a constructor with a boolean to disable overwriting the entire file. Quote
Zcelo12 Posted August 28, 2013 Author Posted August 28, 2013 On 8/27/2013 at 3:26 PM, GotoLink said: 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. Quote
Zcelo12 Posted August 28, 2013 Author Posted August 28, 2013 On 8/28/2013 at 8:59 AM, diesieben07 said: Quote 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. Quote
Zcelo12 Posted August 28, 2013 Author Posted August 28, 2013 Oh my god thank you, it's like i am a blockhead Quote
Zcelo12 Posted August 28, 2013 Author Posted August 28, 2013 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 Quote
Zcelo12 Posted August 28, 2013 Author Posted August 28, 2013 And how I use it to locate the path. Sorry, but I don't understand how to use this method. Quote
Zcelo12 Posted August 29, 2013 Author Posted August 29, 2013 I didn't use the FileWrite/Read methods ever in Java, so i didn't learned it But thank you very much! Quote
Recommended Posts
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.