Close
[obj] obj can be an InputStream
, or an OutputStream
object, or a String
. When obj is a string file path, one of the channels associated with it is closed.
Close[StringToStream["123abc"]]
file=Close[OpenWrite[]]
Closing a file doesn't delete it from the filesystem.
DeleteFile[file];
If two streams are open with the same file, then a Close
by file path closes only one of the streams:
stream1 = OpenRead["ExampleData/numbers.txt"]
stream2 = OpenRead["ExampleData/numbers.txt"]
Close["ExampleData/numbers.txt"]
Usually, the most-recent stream is closed, while the earlier-opened stream still persists:
Read[stream1]
However, one of the streams is closed:
Read[stream2]
Close["ExampleData/numbers.txt"]
Read[stream1]