[英]Uploading a csv file to ftp without creating a physical file locally
I want to create and send a csv file to a remote ftp server,i am using CSVWriter
from Apache Commons
. 我想创建一个csv文件并将其发送到远程ftp服务器,我正在使用来自Apache Commons
CSVWriter
。
At present, I am creating a local temp file, wrapping this file around an Inputstream
, and then uploading this stream to remote ftp server using client.store(<InputStream>,<Filename>)
method. 目前,我正在创建一个本地临时文件,将该文件包装在Inputstream
周围,然后使用client.store(<InputStream>,<Filename>)
方法将此流上传到远程ftp服务器。 The problem here is it is creating a local temp file every time it is executed. 这里的问题是它每次执行时都会创建一个本地临时文件。
I want to get rid of this and be able to create a stream, especially csv stream directly. 我想摆脱这一点,并能够直接创建流,尤其是csv流。 My main idea is to avoid creating a local temp file. 我的主要想法是避免创建本地临时文件。
You can wrap a ByteArrayOutputStream in any kind of Writer, and use that Writer as an argument for the CSVWriter. 您可以将ByteArrayOutputStream包装在任何类型的Writer中,并将该Writer用作CSVWriter的参数。 That way you can extract a byte array, which can be used as an argument for an ByteArrayInputStream. 这样,您可以提取一个字节数组,该字节数组可用作ByteArrayInputStream的参数。
If it's a large amount of data, you can use a combination of PipedInputStream and PipedOutputStream instead of the ByteArray*Streams. 如果数据量很大,则可以使用PipedInputStream和PipedOutputStream的组合,而不是ByteArray * Streams。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.