我已经在GAE blob商店中有一个文本文件。我试图从android访问该文件并将其保存到SD卡中。
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());
}
但是面对上面代码的IO FileNotFoundException。
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
甘蔗有人帮我这个吗?提前谢谢。
注意:我可以使用相同的网址从浏览器访问该文件。