Hi Mark,

Thanks for immediate reply. I checked these conditions, when we tried
to push a file using adb is working fine, but only through the below
code, we are seeing the exception:


public void addFile(String filename) throws Exception{

        InputStream is = this.getInstrumentation().getContext
().getAssets().open(filename);
        File directory = new File
(Environment.getExternalStorageDirectory().getPath()+"/downloads");

        if (!directory.exists()) {
                directory.mkdir();
        }

        File file = new File(directory.getPath()+"/"+filename);
        if (!file.exists() && directory.exists()){
                try {
                    file.createNewFile();
                } catch (IOException e) {
                        Log.d(TAG,"File creation failed for " + file);
                }
        }
        if (file.exists() && file.canWrite()){
            FileOutputStream os = new FileOutputStream(file);
            byte[] b = new byte[1024];
            int len;
            while ((len = is.read(b))>0){
                os.write(b,0,len);
                }
            os.flush();
            os.close();
            is.close();
        }
        else {
            Log.e(TAG, "Failed to write the file to SDCard");
        }
    }

Thanks,
Android user.

On Oct 15, 10:36 am, Mark Murphy <[email protected]> wrote:
> androiduser mobile wrote:
> > Hi all,
>
> > I am facing a weird problem now, I have a piece of code which copies
> > the files from assets folder to sdcard/downloads and is working well
> > for me, but when other user is running this code in his system, he is
> > getting " Parent directory does not exist" exception with
> > file.createNewFile().
> > We both are using the same android SDK. Can anyone suggest what makes
> > it work differently in different systems?
>
> Perhaps the other user does not have an /sdcard/downloads/ directory,
> either because:
>
> 1. You did not create a downloads/ directory, or
>
> 2. The external storage is not at /sdcard and you used that string
> literally rather than Environment.getExternalFileStorage(), or
>
> 3. The user does not have an SD card installed, or...
>
> There are probably other possible causes, but those three come to mind.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> _Android Programming Tutorials_ Version 1.0 In Print!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to