【问题标题】:FileNotFoundException while Unzip file from S3 in scala在scala中从S3解压缩文件时出现FileNotFoundException
【发布时间】:2017-03-10 07:17:10
【问题描述】:

我正在从 S3 获取 Zip 文件,然后尝试解压缩它。 压缩文件内容:- 测试 2 文件夹/ abc日志 xyz.log

代码

val S3Object = getObject(id.bucketName, id.key_fileName)
val zipStreamm = new ZipInputStream(S3Object.getObjectContent)

val entryStream = Stream.continually(zipStreamm.getNextEntry).takeWhile(x => x != null)

val files: Stream[String] = entryStream.map { _ =>  scala.io.Source.fromInputStream(zipStreamm).getLines.mkString("\n") }

错误

Mar 10, 2017 12:48:48 AM com.twitter.finagle.Init$ $anonfun$once$1
INFO: Finagle version 6.42.0 (rev=f48520b6809792d8cb87c5d81a13075fd01c051d) built at 20170203-170145
Mar 10, 2017 12:48:50 AM com.twitter.finagle.util.DefaultMonitor logWithRemoteInfo
WARNING: Exception propagated to the default monitor (upstream address: /127.0.0.1:60721, downstream address: n/a, label: ).
java.io.FileNotFoundException: Test 2/abc.log (Not a directory)
    at java.io.FileOutputStream.open0(Native Method)
    at java.io.FileOutputStream.open(FileOutputStream.java:270)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:101)

【问题讨论】:

    标签: scala amazon-web-services amazon-s3 unzip zipfile


    【解决方案1】:

    正如我从这个异常中看到的,您试图解压缩 Test 2 文件夹中的文件,而不是 Test

    java.io.FileNotFoundException: Test 2/abc.log (Not a directory)
    at java.io.FileOutputStream.open0(Native Method)
    at java.io.FileOutputStream.open(FileOutputStream.java:270)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:101)
    

    你能分享你执行这个操作的代码吗?

    【讨论】:

    • 我错过了什么吗?
    • 不,我使用的是 Finch 服务器。我正在本地测试它。我从 S3 获取文件,但不知道 Y m 在解压缩时遇到问题。
    • 请考虑这个答案:stackoverflow.com/a/32629904/3284193
    • 该解决方案仅在存在单个文件时才有效 不适用于需要解压缩的 Zip 文件
    猜你喜欢
    • 2020-04-01
    • 2020-02-12
    • 2021-09-12
    • 1970-01-01
    • 2020-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多