[Solved] Given the file path find the file extension using Scala?


You could achieve this as follows:

import java.nio.file.Paths

val path = "/home/gmc/exists.csv"
val fileName = Paths.get(path).getFileName            // Convert the path string to a Path object and get the "base name" from that path.
val extension = fileName.toString.split("\\.").last   // Split the "base name" on a . and take the last element - which is the extension.
// The above produces:

extension: String = csv

4

solved Given the file path find the file extension using Scala?