createSafely

fun File.createSafely(content: String? = null, overwrite: Boolean = true): File(source)

Creates a new file if it doesn't already exist, creating parent directories if necessary. If the file already exists, its content will be overwritten. If content is provided, it will be written to the file.

Return

The created file.

Parameters

content

The content to be written to the file. Defaults to null.

overwrite

If true, any existing content will be overwritten. Otherwise, nothing is done.