1. Check out our companion app, Forums for Android! Download from Google Play

Can't save downloaded files to SDCard (or anywhere else)

Discussion in 'Application Development' started by phodat, Nov 24, 2010.

  1. phodat

    phodat New Member
    Thread Starter
    5

    Nov 24, 2010
    4
    0
    5
    I am attempted to download some files off of a web server down to my android phone. I would prefer the download be put on the SDcard but at this point it doesn't matter. I am become quite frustrated with this.

    When I attempt to download, I get all the way to the end without exceptions thrown and I check for its existence and do not find it. In addition I cannot find the files on my SD card when looking via DDMS. When I do a directory check, I do not get any errors that the directory does not exist.

    I suspect some type of permissions issue but I can't seem to find the answer. I have verified that the web page script (PHP) is working by trying on my browser. I am able to down the file to my hearts content


    thanks in advance!!!

    private boolean WriteBytesToFile(String path,byte[] bytes)
    {
    boolean returnval =false;

    try
    {

    File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyDir" + path);

    File directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyDir" + path).getParentFile();
    if (!directory.exists() && !directory.mkdirs()) {
    logger.e("WriteBytesToFile","path does not exist ");
    }

    FileOutputStream fos = openFileOutput(path,MODE_WORLD_READABLE);
    logger.e("WriteBytesToFile","Length of file to write : " +Integer.toString(bytes.length));
    fos.write(bytes);
    fos.flush();
    fos.close();
    if (file.exists())
    {
    logger.e("WriteBytesToFile","File Exists after download");
    returnval = true;
    }
    else
    {
    logger.e("WriteBytesToFile","File Doesn't Exist after download");
    returnval = true;
    }
    }
    catch(Exception ex)
    {
    logger.e("WriteBytesToFile","Exception : " + ex.toString());
    }
    return returnval;
    }

    }
     

    Advertisement

  2. phodat

    phodat New Member
    Thread Starter
    5

    Nov 24, 2010
    4
    0
    5
    Please disregard, I found my error. I was checking a file path that was not relevant to my apps private storage. When I did a search via getFilesDir() the files were there...
     

Share This Page

Loading...