In the code below, if I uncomment the for loop the file no longer gets deleted
val file = "myfile.csv"
//for (line <- Source.fromFile(file).getLines()) { }
new File(file).delete()
If so is there some type of close function that I should be calling?
There is some sort of close that you should be calling:
but this is a bit tedious. If you rewrite the for loop as
you can then
and now your code would become
(which would be a benefit if you’re doing it many times in your code, or if you already maintain your own library of helpful functions and it would be easy to add the closing implicit just once there so you could use it everywhere).