[英]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.