Created
October 26, 2015 15:53
-
-
Save squito/222a28f04a6517aafba2 to your computer and use it in GitHub Desktop.
CanIReadOpenDeletedFiles.scala
This file contains hidden or 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.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