Created
August 22, 2024 15:00
-
-
Save rajvermacas/67ed0d0f765565ab109a27c4d8070c2c to your computer and use it in GitHub Desktop.
Find csv path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.nio.file.{Paths, Path} | |
def getCsvFilePath(fileName: String): Option[Path] = { | |
val resourceUrl = Option(getClass.getClassLoader.getResource(fileName)) | |
resourceUrl.map(url => Paths.get(url.toURI)) | |
} | |
// Example usage: | |
val csvFilePath: Option[Path] = getCsvFilePath("data.csv") | |
csvFilePath match { | |
case Some(path) => println(s"CSV file path: $path") | |
case None => println("CSV file not found") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment