0
㈣被要求使用來自於java.The問題webservice的一個PDF是我不知道怎麼寫上的文件,以便它可以通過PDF很好地看出觀衆。消耗和web服務用Java編寫的PDF
URL url = new URL("http://localhost:9090/xcvbb/rest/integrationservices/getPDF");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/pdf");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
//writing the downloaded data into the file we created
FileOutputStream fileOutput = new FileOutputStream("C:/Users/dkimigho/Downloads/bitarraypdf.pdf");
String output;
System.out.println("Output from Server2 .... \n");
while ((output = br.readLine()) != null) {
fileOutput.write(br.readLine().getBytes());
}
//closed the output stream
fileOutput.close();
///
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
對此的任何幫助將不勝感激。
從HttpURLConnection對象獲取輸入流並寫入到具有pdf擴展名的文件。 –
你可能應該看看iText或其他pdf庫 – 2016-11-24 16:49:13
溼婆我已經嘗試過,但它不工作。一個代碼的例子可能會有所幫助,謝謝。 – Kimigx