Create a folder with a specific name

1

I'm trying to create a folder with a certain name but I do not know why bin + name always appears.

Example: If secondArg = point then the folder name becomes binpoint.

Is it because I'm running at the terminal? Since when I run the terminal I have to go to the project folder and then to the bin in order to execute the class. How can I resolve?

private void makeDir(String secondArg) {
        File theDir = new File(System.getProperty("user.dir") + secondArg);

        // if the directory does not exist, create it
        if (!theDir.exists()) {
            System.out.println("creating directory: " + theDir.getName());
            boolean result = false;

            try{
                theDir.mkdir();
                result = true;
            } 
            catch(SecurityException se){
                //handle it
            }        
            if(result) {    
                System.out.println("Repository " + theDir.getName() + " was been created");  
            }
        }

    }
    
asked by anonymous 16.03.2017 / 00:24

1 answer

0

Missing a folder separator:

private void makeDir(String secondArg) {
        File theDir = new File(System.getProperty("user.dir") + File.separator + 
 secondArg);

        // if the directory does not exist, create it
        if (!theDir.exists()) {
            System.out.println("creating directory: " + theDir.getName());
            boolean result = false;

            try{
                theDir.mkdir();
                result = true;
            } 
            catch(SecurityException se){
                //handle it
            }        
            if(result) {    
                System.out.println("Repository " + theDir.getName() + " was been created");  
            }
        }

 }

I used File.separator instead of bars ( \ or / ) because this is in charge of the running operating system set.

    
16.03.2017 / 00:30