본문 바로가기
Language/Kotlin

2021 - 05 - 11, Kotlin

by Cs.Woo 2021. 5. 13.

코틀린 Create File 예제

import java.io.File
 
fun main(args: Array<String>) {
 
    val fileName = "data.txt"
 
    var file = File(fileName)
 
    // create a new file
    val isNewFileCreated :Boolean = file.createNewFile()
 
    if(isNewFileCreated){
        println("$fileName is created successfully.")
    } else{
        println("$fileName already exists.")
    }
 
    // try creating a file that already exists
    val isFileCreated :Boolean = file.createNewFile()
 
    if(isFileCreated){
        println("$fileName is created successfully.")
    } else{
        println("$fileName already exists.")
    }
 
}

'Language > Kotlin' 카테고리의 다른 글

2021 - 05 - 13, Kotlin  (0) 2021.05.14
2021 - 05 - 12, Kotlin  (0) 2021.05.13
2021 - 05 - 10, Kotlin  (0) 2021.05.13
2021 - 05 - 09, Kotlin  (0) 2021.05.10
2021 - 05 - 08, Kotlin  (0) 2021.05.10