Skip to content

Instantly share code, notes, and snippets.

@rajvermacas
Created August 22, 2024 15:00
Show Gist options
  • Save rajvermacas/67ed0d0f765565ab109a27c4d8070c2c to your computer and use it in GitHub Desktop.
Save rajvermacas/67ed0d0f765565ab109a27c4d8070c2c to your computer and use it in GitHub Desktop.
Find csv path
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