Skip to content

Instantly share code, notes, and snippets.

@squito
Created October 26, 2015 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squito/222a28f04a6517aafba2 to your computer and use it in GitHub Desktop.
Save squito/222a28f04a6517aafba2 to your computer and use it in GitHub Desktop.
CanIReadOpenDeletedFiles.scala
import java.io._
object CanIReadOpenDeletedFile {
def main(args: Array[String]): Unit = {
try {
val f = new File("deleteme")
val out = new FileOutputStream(f)
out.write(1)
out.close()
val in = new FileInputStream(f)
f.delete()
val out2 = new FileOutputStream(f)
out2.write(2)
out2.close()
assert(f.exists())
val in2 = new FileInputStream(f)
assert(in.read() == 1)
assert(in.read() == -1)
assert(in2.read() == 2)
assert(in2.read() == -1)
in.close()
in2.close()
println("Yes! You can read files that were deleted after they were opened!")
} catch {
case ex: Exception =>
println("No, you cannot read files that were deleted after they were opened")
throw ex
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment