「Kotlin」exists()でフォルダの存在を確認するサンプル

書式
public static boolean exists(Path path,LinkOption… options)
public static boolean notExists(Path path,LinkOption… options)
使用例

import java.nio.file.Files
import java.nio.file.Paths

fun main() {
    val dA = "C:\\data\\sub1"
      val dB = "C:\\data\\test"
    val pA = Paths.get(dA)
      val pB = Paths.get(dB)

    if (Files.exists(pA)) {
        println("フfolder A exist")
    }
    if (Files.notExists(pA)) {
        println("folder A is not exist")
    }
      
      if (Files.exists(pB)) {
        println("folder B exist")
    }
    if (Files.notExists(pB)) {
        println("folder B is not exist")
    }
}

実行結果
>kotlinc arkgame.kt -include-runtime -d arkgame.jar
>kotlin arkgame.jar
folder A is not exist
folder B exist

Kotlin

Posted by arkgame