繁体   English   中英

Java中的临时目录被覆盖

[英]Temp dir in java being overwritten

我有一个tar.gz格式的文件。 我读了它的路径,然后尝试将其写入我创建的临时目录中。 目录以文件形式覆盖。 我究竟做错了什么? 我在scala中执行此操作,但在下面使用了Java类。

def restore(id: String) = {
    Future {
      val sourceDir = getSourceFile(id)
      val f = {
        new File(sourceDir)
      }
      if (!f.exists())
        throw ResourceNotFoundException(s"Failed")

      val tmpDir = Files.createTempDirectory("restoreMe")

      val p = Paths.get(s"${tmpDir.toAbsolutePath().toString}/")
      Files.copy(f.toPath, p, StandardCopyOption.REPLACE_EXISTING);
    }
  }

用这个

Path src = f.toPath
Files.copy(src, p.resolve(src.getFileName()), StandardCopyOption.REPLACE_EXISTING);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM