라이브러리를 사용하여 파일을 다운로드하고 저장된 바이트를 인쇄하려면 어떻게해야합니까? 사용해 보았습니다.java apache commons를 사용하여 파일을 다운로드 하시겠습니까?
import static org.apache.commons.io.FileUtils.copyURLToFile;
public static void Download() {
URL dl = null;
File fl = null;
try {
fl = new File(System.getProperty("user.home").replace("\\", "/") + "/Desktop/Screenshots.zip");
dl = new URL("http://ds-forums.com/kyle-tests/uploads/Screenshots.zip");
copyURLToFile(dl, fl);
} catch (Exception e) {
System.out.println(e);
}
}
하지만 바이트 또는 진행률 막대를 표시 할 수 없습니다. 어떤 방법을 사용해야합니까?
public class download {
public static void Download() {
URL dl = null;
File fl = null;
String x = null;
try {
fl = new File(System.getProperty("user.home").replace("\\", "/") + "/Desktop/Screenshots.zip");
dl = new URL("http://ds-forums.com/kyle-tests/uploads/Screenshots.zip");
OutputStream os = new FileOutputStream(fl);
InputStream is = dl.openStream();
CountingOutputStream count = new CountingOutputStream(os);
dl.openConnection().getHeaderField("Content-Length");
IOUtils.copy(is, os);//begin transfer
os.close();//close streams
is.close();//^
} catch (Exception e) {
System.out.println(e);
}
}
어떻게 아파치를 사용하겠습니까? fl = new File (System.getProperty ("user.home"). replace ("\\", "/") + "/Desktop/Screenshots.zip"); dl = 새 URL ("http://ds-forums.com/kyle-tests/uploads/Screenshots.zip"); OutputStream os = 새로운 FileOutputStream (fl); InputStream is = dl.openStream(); CountingOutputStream 개수 = 새 CountingOutputStream (os); dl.openConnection().getHeaderField ("Content-Length"); IOUtils.copy (is, os); // 전송 시작 내가 제대로하고 있습니까? – Kyle
질문에 위의 코드를 추가 하시겠습니까? 읽을 수 없습니다. 나는 도우려고 노력할 것이다. – gigadot
코드를 추가하여 도움을 주셔서 감사합니다. – Kyle