Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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();
                }
        }
    }

  • Author
  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.

  • Author
  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.

  • 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

  • Author

And how I use it to locate the path. Sorry, but I don't understand how to use this method.

  • Author

I didn't use the FileWrite/Read methods ever in Java, so i didn't learned it :D

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.