0
   File albumF = getVideoAlbumDir();
   String path = albumF.getAbsolutePath();

// path =/storage/emulated/0/Pictures/.MyImages (Hidden folder)
// fileSelected.fileName()=IMG_20140417_113847.jpg

   File localFile = new File(path + "/" + fileSelected.fileName());

        Log.v("", "file exist===" + localFile.exists());
        if (!localFile.exists()) {
            Log.v("", "inside if===");
            Log.v("", "Parent Filet===" + localFile.getParentFile());
            localFile.getParentFile().mkdirs();
            // localFile.createNewFile();
            copy(fileSelected, localFile);
        } else {
            Log.v("", "inside else===");
            mCurrentPhotoPath = localFile.getAbsolutePath();
            uploadMediaFile();
        }

This copy method copies data from dropbox file to my local storage.

private void copy(final Entry fileSelected, final File localFile) {
        final ProgressDialog pd = ProgressDialog.show(ChatActivity.this,
                "Downloading...", "Please wait...");
        new Thread(new Runnable() {

            @Override
            public void run() {
                BufferedInputStream br = null;
                BufferedOutputStream bw = null;
                DropboxInputStream fd;
                try {
                    fd = mDBApi.getFileStream(fileSelected.path,
                            localFile.getAbsolutePath());
                    br = new BufferedInputStream(fd);
                    bw = new BufferedOutputStream(new FileOutputStream(
                            localFile));

                    byte[] buffer = new byte[4096];
                    int read;
                    while (true) {
                        read = br.read(buffer);
                        if (read <= 0) {
                            break;
                        }
                        bw.write(buffer, 0, read);
                    }
                    pd.dismiss();

                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    android.os.Message msg = new android.os.Message();
                    msg.arg1 = 100;
                    if (msg.arg1 >= 100) {
                        progressHandler.sendMessage(msg);
                        mCurrentPhotoPath = localFile.getAbsolutePath();
                    }

                } catch (DropboxException e) {
                    e.printStackTrace();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if (bw != null) {
                        try {
                            bw.close();
                            if (br != null) {
                                br.close();
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }).start();

I am creating file in a folder using localFile.getParentFile().mkdirs(); I got above error when I upload this file to server.

how to fix this?

Aniket Bhosale
  • 651
  • 2
  • 11
  • 14

1 Answers1

3

If you've tried all other options - and problem still persists - then maybe you have a case when the file you want to create matches name of already existing directory.(which might be earlier created my some call to mkdirs() maybe accidentally). Example: You want to save file Test\test.pdf but you already have folder Test\Test.pdf\

Taras
  • 488
  • 6
  • 21