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 7026773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:09:42+00:00 2026-05-28T00:09:42+00:00

I was just wondering if the code I made will work to create multiple

  • 0

I was just wondering if the code I made will work to create multiple directories within each other. I used this as a reference.

        String username = enterUserTF.getText(); //the username the user enters in a textfield.

        boolean myGamesFolderSuccess = new File(System.getProperty("user.home"), "My Games").mkdir();

        boolean mainFolderSuccess = new File("My Games", "Type King").mkdir();

        boolean userSuccess = new File("TypeKing", username).mkdir(); //creates a folder with the users username.

        if(myGamesFolderSuccess){
            if(mainFolderSuccess){
                if(userSuccess){
                    System.out.println("Directory " + username + " created.");

                        File f = new File(username + "/test.txt");
                        if(!f.exists()){
                            try {
                                f.createNewFile();

                            } catch (IOException e) {
                                e.printStackTrace();
                                System.out.println("Could not create user's file.");
                            }
                        }
                    }   
                }
            }
        }

So to sum up the above, I made the the first directory “My Games” in user.home, then placed my game’s name, “Type King” in that directory, and whenever the user enters a username, I want a directory to be created that is their username. File f just checks for a file in the username directory.

  • 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-28T00:09:43+00:00Added an answer on May 28, 2026 at 12:09 am

    It is recommended to use the mkdirs method of the File class instead of checking multiple status flags when creating nested directories. Also, never use concatenation for creating File objects/paths.

    Also, if you want your game to be portable, make sure you don’t have special characters in your directory names like a space etc.Why are you asking user for the name instead of retrieving it from user.name system property? Something like this should work:

    String username = System.getProperty("user.name");
    File myGamesDir = new File(System.getProperty("user.home"), "my-games");
    File typeKingDir = new File(myGamesDir, "type-king");
    File userDir = new File(typeKingDir, username);
    boolean userSuccess = userDir.mkdirs();
    if(userSuccess){
        System.out.println("Directory " + username + " created.");
        File f = new File(userDir, "test.txt");
        if(!f.exists()){
            try {
                f.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("Could not create user's file.");
            }
        }
    

    }

     

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just wondering why no code-behind or helpers were made to work with
just wondering if someone can help me make this code work properly and be
Just wondering is this kind of code recommended to increase performance? void functionCalledLotsofTimes() {
I use log4net in just about every code project. I was wondering what other
Hey, I'm just wondering what code I could use to auto change the size
Just wondering if a .NET app can be compiled down to native machine code
Just wondering, if I install a Windows service from 64-bit process (service code embedded
Just wondering what the difference between BeginInvoke() and Invoke() are? Mainly what each one
So I have made a little piece of code that will insert and manipulate
I'm working on a custom dropdown that I made, just wondering if I could

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.