简体   繁体   English

如何创建新文件夹?

[英]How to create a new folder?

Or more specifically, how to create a new folder with a random name in scala? 或者更具体地说,如何在scala中创建一个随机名称的新文件夹?

In Java the code was this: 在Java中代码是这样的:

  val folderPath: Path = Paths.get("src/test/resources/test-documents/")
  val tmpDir: Path = Files.createTempDirectory(folderPath, null)

thanks to all 谢谢大家

The same calls will work in Scala. 相同的调用将在Scala中起作用。 All of the Java APIs are interoperable. 所有Java API都是可互操作的。

Generally Java code work fine in Scala environment if the java class files include properly. 通常,如果java类文件包含正确,Java代码在Scala环境中可以正常工作。

import java.nio.file.{Path, Paths, Files}

val folderPath: Path = Paths.get("src/test/resources/test-documents/")
var tmpDir: Path = Files.createTempDirectory(folderPath, null)

This code works fine in scala to create new temp directory. 此代码在scala中正常工作以创建新的临时目录。

In fact, it seemed strange that does not work. 事实上,似乎很奇怪,这是行不通的。 The problem is that I expected the folder were created at one point and instead was created at root level, and rightly so. 问题是我希望文件夹是在一个点上创建的,而是在根级别创建的,这是正确的。

Sorry! 抱歉!

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

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