Uploading a csv file to ftp without creating a phy

2019-09-16 10:42发布

I want to create and send a csv file to a remote ftp server,i am using CSVWriter from Apache Commons.

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. 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. My main idea is to avoid creating a local temp file.

标签: java ftp stream
1条回答
狗以群分
2楼-- · 2019-09-16 11:16

You can wrap a ByteArrayOutputStream in any kind of Writer, and use that Writer as an argument for the CSVWriter. That way you can extract a byte array, which can be used as an argument for an ByteArrayInputStream.

If it's a large amount of data, you can use a combination of PipedInputStream and PipedOutputStream instead of the ByteArray*Streams.

查看更多
登录 后发表回答