Kotlin – Read, Write, Modify, Delete, and List Files

In this article, we will cover how to read, write, modify, delete, and list files in Kotlin and compare them with Java equivalents. Table of contents 1. Reading a File in Kotlin 2. Writing to a File in Kotlin 3. Modifying a File in Kotlin 4. Deleting a File in Kotlin 5. Listing Files in …

Read more

How to delete a temporary file in Java

In Java, we can use the NIO Files.delete() or Files.deleteIfExists() to delete a temporary file, it works the same like delete a regular text file. // create a temporary file Path path = Files.createTempFile(null, ".log"); // delete Files.delete(path); // or if(Files.deleteIfExists(path)){ // success }else{ // file does not exist } 1. Delete Temporary File – …

Read more

How to delete a file in Java

In Java, we can use the NIO Files.delete(Path) and Files.deleteIfExists(Path) to delete a file. 1. Delete a file with Java NIO 1.1 The Files.delete(Path) deletes a file, returns nothing, or throws an exception if it fails. DeleteFile1.java package com.mkyong.io.file; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class DeleteFile1 { public static void main(String[] args) { …

Read more