0

I have make code to make directory on click event of button. But I can't create directory. Previously, I could do it easily but now it has some trouble and I don't get success. Please help on this.

Code:

button1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Username = username.getText().toString();
                Password = password.getText().toString();
                if (Username.length() == 0) {

                    Toast.makeText(getBaseContext(), "Please Fill Username ",
                            Toast.LENGTH_LONG).show();
                } else if (Password.length() == 0) {
                    Toast.makeText(getBaseContext(), "Please Fill Password ",
                            Toast.LENGTH_LONG).show();

                } else {
                    SaxParser(Username, Password);
                    //new AddTask().execute();

                    if (str_getValue.equalsIgnoreCase("0")) {
                        Toast.makeText(getBaseContext(),
                                "Incorrect Username or Password",
                                Toast.LENGTH_LONG).show();
                    } else {
                        File folder = new File(Environment
                                .getExternalStorageDirectory()
                                + "/audiometer/video");

                        boolean success = false;
                        if (!folder.exists()) {
                            success = folder.mkdir();
                        }
                        if (!success) {
                            // Do something on success
                            if(login_checkBox_remember.isChecked()==true)
                            {

                                SavePreferences("MEM1",Username);
                                SavePreferences("MEM2",Password);
                                SavePreferencesBool("flag",true);
                            }   

                            i.putExtra("value", str_getValue);
                            i.putExtra("machineName", str_Machinename);

                            startActivity(i);
                        } else {

                        }

                    }
                }
            }

        });

I have also give permission of WriteExternalStorage in manifest.

Puck
  • 2,080
  • 4
  • 19
  • 30
Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133

2 Answers2

1

you have used "/audiometer/video" which mean you are creating directory in to directory. you can not do it programatically. if you want to do this the first you need to created ""/audiometer" folder and then you need to create "video" in it. you can not achieve both at a time. Change your code & try again.

Also check my answer here for Java ME Application.

Community
  • 1
  • 1
Lucifer
  • 29,392
  • 25
  • 90
  • 143
1

have you checked if the directory exists already?

try it in this way:

boolean success = folder.exists();

if (!success)
    success = folder.mkdir();

if (success) {
    // Do something on success
}
waqaslam
  • 67,549
  • 16
  • 165
  • 178