2009-12-07 9 views

답변

0

어떤 종류의 파일이 아니지만 this 테스트 코드가 도움이 될 수 있습니다. 다른 시험에서 답을 찾으려하지 마십시오.

+0

당신은 http://stackoverflow.com/questions에 문제 봐주세요 수 (... 버튼, 입력, 앵커를) 다운로드하려는 파일에 대한 링크를 가진 요소입니다/2131049/problem-in-htmlunit-api-for-java-headless-browser –

0

나는 이미 문제를 해결했을 것이지만,이 질문은 "htmlunit download"를 검색 할 때 Google의 최고 결과에 대한 것이므로 여기에 표준 해결책이 있습니다. downloadLink

try { 
    InputStream is = downloadLink.click().getWebResponse().getContentAsStream(); 
    try { 
     File f = new File("filename.extension"); 
     OutputStream os = new FileOutputStream(f); 
     byte[] bytes = new byte[1024]; // make it bigger if you want. Some recommend 8x, others 100x 
     while (read = is.read(bytes)) { 
      os.write(bytes, 0, read); 
     } 
     os.close(); 
     is.close(); 
    } catch (IOException ex) { 
     // Exception handling 
    } 
} catch (IOException ex) { 
    // Exception handling 
}