0
IvがjavaのWebサービスからpdfを消費するよう依頼されました。問題は私がpdfでよく見られるようにファイルに書き込む方法を知らないことです視聴者。aを消費し、Javaのwebserviceから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ライブラリ –
Shiva私はそれを試してみましたが、コードの例が役に立ちませんでした。ありがとうございました。 – Kimigx