내가 예를 http://www.math.uni-goettingen.de/zirkel/loesungen/blatt15/loes15.pdf
이 링크, 웹에서 PDF 파일을 다운로드해야 스트림. 나는 Streams를 사용하여 그것을해야만한다. 이미지가 나와 잘 작동합니다.자바를 사용하여 웹에서 PDF 파일을받는 방법
public static void main(String[] args) {
try {
//get the url page from the arguments array
String arg = args[0];
URL url = new URL("https://cs7065.vk.me/c637923/v637923205/25608/AD8WhOSx1ic.jpg");
try{
//jpg
InputStream in = new BufferedInputStream(url.openStream());
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[131072];
int n = 0;
while (-1!=(n=in.read(buf)))
{
out.write(buf, 0, n);
}
out.close();
in.close();
byte[] response = out.toByteArray();
FileOutputStream fos = new FileOutputStream("borrowed_image.jpg");
fos.write(response);
fos.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
그러나 PDf에서는 작동하지 않습니다. 무엇이 문제 일 수 있습니까?
수단을 "작동하지 않는"무엇을 명확히하십시오. 코드가 예외를 던지고 있습니까? 읽을 수없는 pdf 파일을 생성합니까? 다른 것? – mangotang
@mangotang, 그것이 unreadble PDF 파일 – Vladislav
을 만드는 난 당신의 코드에서 구문 오류를 수정하고, 샘플 PDF를 얻기 위해이 URL을 사용하고, 코드가 잘 작동 : http://www.pdf995.com/samples/pdf .pdf – mangotang