주어진 URL 경로에서 .PDF 파일을 다운로드 할 수있는 앱을 작성했습니다. 하지만 VM에서 실행할 때 내 앱에서 파일을 다운로드 할 수 없다는 것을 알았습니다. 그래서 DownloadManager을 VM에 시도했지만 여전히 파일을 다운로드 할 수 없습니다. 그리고 DownloadManage가 중지되고 항상 "OnGoing"을 표시했습니다. 아무도 나에게 이유와이 문제를 해결하는 방법을 말할 수 있습니까? 미리 감사드립니다. PS : *이 내 코드가 잘못 생각 해달라고하지만, 안드로이드 에뮬레이터의 문제 :이Android : 가상 머신이 웹 사이트에서 파일을 다운로드 할 수 없습니다.
public File writeFileToSDCard(String path,String fileName,InputStream in){
File file = null;
OutputStream out = null;
try{
if(!createDir(path)){
Log.e("FileUtils.java", "writeFileToSDCard().createDir() failed!");
}else{
Log.e("FileUtils.java", "writeFileToSDCard().createDir() Successed!");
}
file = createFile(path+fileName);
out = new FileOutputStream(file);
byte buffer[] = new byte[128];
//write the file
do{
int length = in.read(buffer);
if(length != -1){
Log.e("FileUtils.java", "Writing to card!");
out.write(buffer, 0, length);
}else{
break;
}
}while(true);
}catch(Exception e){
Log.e("FileUtils.java", "writeFileToSDCard() failed!");
}finally {
try{
out.close();
}catch (Exception e) {
Log.e("FileUtils.java", "writeFileToSDCard() finally failed!");
}
}
return file;
}
* PSS 쓰기?
다운로드하려는 파일에 URL과 다운로드하려는 코드를 게시하십시오. – Bobbake4
VM에 의해, 당신은 안드로이드 에뮬레이터를 의미합니까? 실제 장치에서 파일을 다운로드 해 보셨습니까? –
@Aki yes, android emulator. –