scala - 解压时如何在 Scala 中压缩多个文件而不创建文件夹
问题描述
所以我有一个文件位置列表。我已经将文件下载到这些文件位置,所以从技术上讲,它们已经有内容了。这些只是 .txt 文件。
我的问题是,当我有多个由于此代码而被压缩的文件时,当我在文件管理器(mac 中的 Finder)中解压缩它时,解压缩的文件包含一个包含文本文件的文件夹。解压缩时我不想看到任何文件夹。我怎样才能解决这个问题?这是我的代码顺便说一句。
def zipFiles(fileLocations: List[String], zipOutputFilename: String): Unit = {
val a =
for {
fos <- managed(new FileOutputStream(zipOutputFilename))
zos <- managed(new ZipOutputStream(fos))
} yield {
for {
fileLoc <- fileLocations
} {
val file = new File(fileLoc)
zos.putNextEntry(new ZipEntry(fileLoc))
val in = new BufferedInputStream(new FileInputStream(file))
var b = in.read()
while (b > -1) {
zos.write(b)
b = in.read()
}
in.close()
zos.closeEntry()
}
zos.close()
}
a.map(identity).tried
()
}
解决方案
使用new ZipEntry(file.getName)
而不是new ZipEntry(fileLoc)
.
推荐阅读
- javascript - 在 if 语句 VUE 中等待来自 Promise 的数据
- javascript - 想用ngif加载div里面的img,当ngif==false
- c# - 在标题单击时对 DGV 进行排序
- python - 如何在 Eclipse Python (PyDev) 中获取警告 - “未使用的函数”?
- azure-data-lake - 为 JSON 文件分配的 ADLA AU
- xamarin - 地理定位器位置权限
- php - 在同一个函数中调用 wp_mail() 两次(第二个不会发送)
- java - 再次点击后如何取消点击的ListItem的选中状态?
- c# - 将带有构造函数的对象保存到 xml
- c# - Webbrowsercontrol 未在自定义任务窗格中加载 URL - Word 插件