如何解决Java中的String IFile
我有一个Map
Map<String,String> fileMap = new HashMap<>();
fileMap.put("test1.txt","Content of test1");
fileMap.put("test2.txt","Content of test2");
如何为每个条目创建IFile?
解决方法
关于您在评论中所说的,这应该可以完成工作:
Map<String,String> fileMap = new HashMap<>();
fileMap.put("test1.txt","Content of test1");
fileMap.put("test2.txt","Content of test2");
FileOutputStream fos = new FileOutputStream("multiCompressed.zip");
ZipOutputStream zipOut = new ZipOutputStream(fos);
for (Map.Entry<String,String> file : fileMap.entrySet()) {
File fileToZip = new File(file.getKey());
FileWriter writer = new FileWriter(fileToZip);
writer.write(file.getValue());
FileInputStream fis = new FileInputStream(fileToZip);
ZipEntry zipEntry = new ZipEntry(fileToZip.getName());
zipOut.putNextEntry(zipEntry);
byte[] bytes = new byte[1024];
int length;
while ((length = fis.read(bytes)) >= 0) {
zipOut.write(bytes,length);
}
fis.close();
}
zipOut.close();
fos.close();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。