如何将 ZipInputStream 读入 CharArrayReader
现在我正在使用 Google App Engine (GAE) 开发一个应用程序。 GAE 不允许我创建临时文件夹来存储我的 zip 文件并从中读取。唯一的方法就是从记忆中读取它。该 zip 文件包含 6 个 CSV 文件,我需要将其读入 CSVReader。
//part of the code
MultipartFormDataRequest multiPartRequest = null;
Hashtable files = multiPartRequest.getFiles();
UploadFile userFile = (UploadFile)files.get("bootstrap_file");
InputStream input = userFile.getInpuStream();
ZipInputStream zin = new ZipInputStream(input);
我如何将 ZipInputStream 读入 char[] 中,这是为我的 CSVReader 对象创建 CharArrayReader 所需的。
CSVReader reader = new CSVReader(CharArrayRead(char[] buf));
Right now i am developing an application using Google App Engine (GAE). GAE doesnt allow me to create temp folder for me to store my zipfile and read from it. The only way is to read it from memory. The zipfile contains 6 CSV files which i need to read it into CSVReader.
//part of the code
MultipartFormDataRequest multiPartRequest = null;
Hashtable files = multiPartRequest.getFiles();
UploadFile userFile = (UploadFile)files.get("bootstrap_file");
InputStream input = userFile.getInpuStream();
ZipInputStream zin = new ZipInputStream(input);
How do i read ZipInputStream into char[] which is needed to create CharArrayReader for my CSVReader object.
CSVReader reader = new CSVReader(CharArrayRead(char[] buf));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用 InputStreamReader 包装 ZipInputStream 以将字节转换为字符;然后调用 inputStreamReader.read(char[] buf, int offset, int length) 来填充 char[] 缓冲区,如下所示:
如果您的 CharArrayRead 实际上是 java.io.CharArrayReader,则无需将其加载到char[] 并且你最好使用这样的代码:
如果你只有一个压缩文件(试图绕过 1MB 限制),那么这将起作用:
Wrap the ZipInputStream with an InputStreamReader to convert from bytes to chars; then call inputStreamReader.read(char[] buf, int offset, int length) to fill your char[] buffer, like this:
if your CharArrayRead is actually a java.io.CharArrayReader, then there is no need to load it into a char[] and you'd be better off with code like this:
If you just have a single zipped file (trying to get around the 1MB limitation) then this will work: