将CSV文件上传到ftp而不在本地创建物理文件 [英] Uploading a csv file to ftp without creating a physical file locally

查看:222
本文介绍了将CSV文件上传到ftp而不在本地创建物理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个csv文件并将其发送到远程ftp服务器,我正在使用Apache Commons中的CSVWriter.

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

目前,我正在创建一个本地临时文件,将该文件包装在Inputstream周围,然后使用client.store(<InputStream>,<Filename>)方法将此流上传到远程ftp服务器.这里的问题是它每次执行时都会创建一个本地临时文件.
我想摆脱这一点,并能够直接创建流,尤其是csv流.我的主要想法是避免创建本地临时文件.

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.

推荐答案

您可以将ByteArrayOutputStream包装在任何类型的Writer中,并将该Writer用作CSVWriter的参数.这样,您可以提取一个字节数组,该字节数组可用作ByteArrayInputStream的参数.

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.

如果数据量很大,则可以使用PipedInputStream和PipedOutputStream的组合来代替ByteArray * Streams.

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

这篇关于将CSV文件上传到ftp而不在本地创建物理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆