Skip to content

Instantly share code, notes, and snippets.

@hhimanshu
Last active January 9, 2023 17:45
Show Gist options
  • Save hhimanshu/6b1a2b7bf49f50ac602ce5928b74b2bd to your computer and use it in GitHub Desktop.
Save hhimanshu/6b1a2b7bf49f50ac602ce5928b74b2bd to your computer and use it in GitHub Desktop.
Copy File inside Jar to External Location
import java.io.File
import java.net.URL
// Note: This has dependency on apache commons-io
import org.apache.commons.io.FileUtils
object LoadFile extends App {
override def main(args: Array[String]): Unit = {
val fileName = "myfileJarFile.json"
val path: URL = getClass.getClassLoader.getResource("v410.all/" + fileName)
val destination = new File("/Users/harit/Downloads/" + fileName)
FileUtils.copyURLToFile(path, destination)
println(s"copied $path to $destination")
}
}
@hhimanshu
Copy link
Author

scala -classpath target/scala-2.11/my.jar LoadFile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment