2011-07-05 11 views
0

에 저장하고이 URL을 실행하여 .mp4 형식으로 저장하려고하면 FileNotFound 예외가 발생합니다. 사전에URL을 from android

String storage = Environment.getExternalStorageState(); 
    Log.i("System out", "" + storage); 
    File rootsd = Environment.getExternalStorageDirectory(); 
    Log.d("ROOT PATH", "" + rootsd.getAbsolutePath()); 

    File mydir = new File(rootsd.toString() + "/unplugger"); 
    Log.i("DIR PATH", "" + mydir.getAbsolutePath()); 
    mydir.mkdir(); 

    URL u; 
    try { 
     u = new URL(
       "http://vimeo.com/moogaloop/play/clip:7926539/5cd4f7989ee0cb5018c131260aa1fc8c/1309860388/"); 

     HttpURLConnection c = (HttpURLConnection) u.openConnection(); 
     c.setRequestMethod("GET"); 
     c.setDoOutput(true); 

     c.connect(); 

     FileOutputStream f = new FileOutputStream(new File(mydir + "/" 
       + "myVideo.mp4")); 

     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(); 
     c.disconnect(); 
    } catch (MalformedURLException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
     Log.i("System out","malformed :"+e.getMessage()); 
     Log.i("System out","malformed :"+e.toString()); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
     Log.i("System out","io: "+e.getMessage()); 
     Log.i("System out","io: "+e.toString()); 
    } 

감사 : 같은 URL은 내가 .MP4 형식 여기 http://vimeo.com/moogaloop/play/clip:7926539/5cd4f7989ee0cb5018c131260aa1fc8c/1309860388/

내 코드가 같이 저장, 브라우저에서 시도합니다.

+0

어느 라인이 오류가 발생합니다? –

+1

22 개의 질문을했지만 대답을 수락하지 않았습니다. –

답변

2

변경이 작품은 :

new File(mydir + "/" + "myVideo.mp4") 

대신이 될하려면

new File(mydir, "myVideo.mp4") 
+0

실제로 문제는 URL에서 데이터를 가져 오는 것입니다 (이 줄의 filenotfound 예외 : InputStream in = c.getInputStream(); ) –

+0

HttpURLConnection이 자동으로 리디렉션을 처리한다고 생각하지 않습니다. 링크가 파일 자체를 직접 가리 키지 않으므로 아마도 3xx HTTP 응답을 얻고있을 것입니다. 이것은 리다이렉션 (redirect)이 될 것이고 어떤 내용도 포함하지 않을 것이므로 내용을 얻으려고하면'FileNotFound'를 던질 것입니다. 안드로이드에서 사용할 수있는 Apache의 HttpClient 라이브러리를 사용하는 것이 좋습니다. HttpURLConnection을 사용하지 마십시오. –