![](/img/trans.png)
[英]I want to get the real path of a file in java by using the request method getRealPath()but it is deprecated now i want an alternate to it
[英]I have genrated the pdf file now i dont want to download the file but i want to upload the file directly on ftp using java
所以我現在每次運行代碼時都將html轉換為pdf文件,該文件被下載並且其工作正常,但我不想下載,而是想在文件生成后立即直接上傳到ftp服務器上,下面是我的代碼
@GET
@Path("/test")
public String test(@Context HttpServletResponse response){
String strHtml ="<html><body>"Here is my html"</body></html>";
String filename=test.pdf";
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
@SuppressWarnings( "deprecation")
org.w3c.dom.Document doc = builder.parse( new StringBufferInputStream(strHtml.replaceAll("&" , "&")));
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument((org.w3c.dom.Document) doc, null);
renderer.layout();
response.setHeader( "Cache-Control","private" );
response.setHeader( "Pragma","expires" );
response.setHeader( "Content-Disposition", "attachment; filename=\"" + filename + "\"");
renderer.createPDF(response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();
}
我建議使用Apache Commons Net庫來使用FTP。 這是一個簡單的FTP客戶端示例 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.