1

I am having a text file in GAE blob store already. I tried to access that file from android and save it into SD card.

   String filename = 'HelloWorld.txt';
   String fileURL = "http://bakupand.appspot.com/download?blob-key=AMIfv95pR-81U2oXcOQ1wkj_6iwKsfRkb7Eah6LYpdN08KTeHM0Db2FUCHRHP-ijs0qVc8UFnGSeH4Tu1RlcQCn9d3gkvZK8v9FCl09aknEztvL7xEpTgS2ptL0liAxQThiyKz6SQJa_-M-9MRS8WoKzgWmZxU_ReSZ0ZSVCcubdpPoi5HFPL1w";

   try {
        File sdCard = Environment.getExternalStorageDirectory();
        File dir = new File(sdCard.getAbsolutePath() + "/doc");
        dir.mkdirs();
        URL u = new URL(fileURL);
        HttpURLConnection c = (HttpURLConnection) u.openConnection();
        c.setRequestMethod("GET");
        c.setDoOutput(true);
        c.connect();
        FileOutputStream f = new FileOutputStream(new File(dir, filename));

        InputStream in = c.getInputStream();

        byte[] buffer = new byte[1024];
        int len1 = 0;
        while ((len1 = in.read(buffer)) > 0) {
            f.write(buffer, 0, len1);
        }
        f.close();
    } catch (Exception e) {
        e.printStackTrace();
        Log.d("Downloader", e.getMessage());
    }

But facing IO FileNotFoundException for the above code.

05-12 19:25:49.067: W/System.err(15327): java.io.FileNotFoundException: http://bakupand.appspot.com/download?blob-key=AMIfv95pR-81U2oXcOQ1wkj_6iwKsfRkb7Eah6LYpdN08KTeHM0Db2FUCHRHP-ijs0qVc8UFnGSeH4Tu1RlcQCn9d3gkvZK8v9FCl09aknEztvL7xEpTgS2ptL0liAxQThiyKz6SQJa_-M-9MRS8WoKzgWmZxU_ReSZ0ZSVCcubdpPoi5HFPL1w

Cane anyone help me on this? Thanks in advance.

Note: I could access the that file from browser with the same url.

4

0 回答 0