Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6989995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:17:16+00:00 2026-05-27T19:17:16+00:00

Okay, I’m trying to create a custom client for Minecraft (don’t worry, my question

  • 0

Okay, I’m trying to create a custom client for Minecraft (don’t worry, my question has nothing to do with Minecraft in particular), and I added an abstract class to manage a configuration file using Java’s built-in Properties system. I have a method that loads a properties file or creates it if it doesn’t already exist. This method is called at the beginning of all my other methods (although it only does anything the first time its called).

The properties file gets created just fine when I run Minecraft the first time, but somehow when I run it the second time, the file gets blanked out. I’m not sure where or why or how I’m wiping the file clean, can someone please help me? Here’s my code; the offending method is loadConfig():

package net.minecraft.src;

import java.util.*;
import java.util.regex.*;
import java.io.*;

/**
 * Class for managing my custom client's properties
 *
 * @author oxguy3
 */
public abstract class OxProps
{
    public static boolean configloaded = false;
    private static Properties props = new Properties();
    private static String[] usernames;

    public static void loadConfig() {
        System.out.println("loadConfig() called");
        if (!configloaded) {
            System.out.println("loading config for the first time");
            File cfile = new File("oxconfig.properties");
            boolean configisnew;

            if (!cfile.exists()) {
                System.out.println("cfile failed exists(), creating blank file");
                try {
                    configisnew = cfile.createNewFile();
                } catch (IOException e) {
                        e.printStackTrace();
                        configisnew=true;
                }
            } else {
                System.out.println("cfile passed exists(), proceding");
                configisnew=false;
            }

            FileInputStream cin = null;
            FileOutputStream cout = null;
            try {
                cin = new FileInputStream(cfile);
                cout = new FileOutputStream(cfile);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }

            if (!configisnew) { //if the config already existed
                System.out.println("config already existed");
                try {
                    props.load(cin);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else { //if it doesn't exist, and therefore needs to be created
                System.out.println("creating new config");
                props.setProperty("names", "oxguy3, Player");
                props.setProperty("cloak_url", "http://s3.amazonaws.com/MinecraftCloaks/akronman1.png");
                try {
                    props.store(cout, "OXGUY3'S CUSTOM CLIENT\n\ncloak_url is the URL to get custom cloaks from\nnames are the usernames to give cloaks to\n");
                    cout.flush();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            String names = props.getProperty("names");
            System.out.println("names: "+names);
            try {
                usernames = Pattern.compile(", ").split(names);
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }
            System.out.println("usernames: "+Arrays.toString(usernames));
            configloaded=true;
        }
    }

    public static boolean checkUsername(String username) {
        loadConfig();
        System.out.println("Checking username...");
        for (int i=0; i<usernames.length; i++) {
            System.out.println("comparing "+username+" with config value "+usernames[i]);
            if (username.startsWith(usernames[i])){
                System.out.println("we got a match!");
                return true;
            }
        }
        System.out.println("no match found");
        return false;
    }

    public static String getCloakUrl() {
        loadConfig();
        return props.getProperty("cloak_url", "http://s3.amazonaws.com/MinecraftCloaks/akronman1.png");
    }
}

If it’s too hard to read here, it’s also on Pastebin: http://pastebin.com/9UscXWap

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:17:16+00:00Added an answer on May 27, 2026 at 7:17 pm

    You are unconditionally creating new FileOutputStream(cfile). This will overwrite the existing file with an empty one. You should only invoke the FileOutputStream constructor when writing a new config file.

    if (configloaded) 
      return;
    File cfile = new File("oxconfig.properties");
    try {
      if (cfile.createNewFile()) {
        try {
          FileOutputStream cout = new FileOutputStream(cfile);
          props.setProperty("names", "oxguy3, Player");
          props.setProperty("cloak_url", "http://...");
          ...
          cout.flush();
        } finally {
          cout.close();
        }
      } else {
        FileInputStream cin = new FileInputStream(cfile);
        try {
          props.load(cin);
        } finally {
          cin.close();
        }
      }
      configloaded=true;
    } catch(IOException ex) {
      e.printStackTrace();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I'm trying to create a list of he folders, and sub-folders and
Okay so I am trying to compare a login textbox password and username with
Okay so I haven't been able to find a question with an answer yet,
Okay, what I'm trying to accomplish is a simple tool tip that, when you
Okay, I really know this has GOT to be the long way around doing
okay, so I'm trying to get a directory of folders and sub folders, but
Okay, This one is pretty simmilar to my last one, but I don't get
Okay, I'm trying to make a quick little class to work as a sort
Okay so I have to create a radix sort for both unsigned ints and
Okay, so I'm trying to set a variable via a javascript method call. However

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.