目前我正在尝试从带有onclicklistener的服务器开始下载文件,我相信我在大部分时间都在取得进展,但我很难知道如何将其保存到外部存储。好像无论我把它放在什么文件位置,它总是试图下载到内部并失败。 我已经在清单中包含了WRITE_EXTERNAL_STORAGE权限。 这是我正在尝试的具体过程的代码。
public void DownloadFromUrl() {
try {
URL url = new URL("http://www.soldier9312-xda.de/svn/leedroid-10/trunk");
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String Path = Environment.getExternalStorageDirectory() + "/Leedroid/SVN";
Log.v("PortfolioManger", "PATH: " + Path);
File file = new File(Path);
file.mkdirs();
FileOutputStream fos = new FileOutputStream(Path);
InputStream is = c.getInputStream();
byte[] buffer = new byte[702];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
} catch (IOException e) {
Log.d("PortfolioManger", "Error: " + e);
}
Log.v("PortfolioManger", "Check: ");
}