【问题】
已经获得了Songtaste中歌曲的地址,比如:
中的真实下载地址是:
然后现在想要去下载这样的文件到Android手机的本地某个文件夹中。
【解决过程】
1.其中,关于自动处理Cookie方面的折腾,详见:
2.参考:
去写代码:public Boolean downlodFile(String url, String fullFilename, HttpParams headerParams)
{
Boolean downloadOk = Boolean.FALSE;
HttpResponse response = getUrlResponse(url, headerParams, null);
if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
HttpEntity respEnt = response.getEntity();
System.out.println("isChunked" + respEnt.isChunked());
System.out.println("Streaming" + respEnt.isStreaming());
Boolean isStream = respEnt.isStreaming();
if(isStream)
{
try {
InputStream fileInStream = respEnt.getContent();
FileOutputStream fileOutStream = new FileOutputStream(new File(fullFilename));
byte[] tmpBuf = new byte[1024];
int tmpLen = 0;
while ( (tmpLen = fileInStream.read(tmpBuf)) > 0 ) {
fileOutStream.write(tmpBuf,0, tmpLen);
}
downloadOk = Boolean.TRUE;
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return downloadOk;
}
最后是可以去获得对应的response,但是结果去创建文件时,出错“java.io.FileNotFoundException: /downloadedMusic.mp3: open failed: EROFS (Read-only file system)”,详细折腾参见:
3.有待后续。