Here are the answers:
- Use
System.IO.File
, please see:
http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx[^]. - There is no such concept. The concept is: you open file/stream and write to it. The file is finally saved (flashed) on disk when you close it. You can also explicitly flash. If a class implements the interface
IDisposable
, you can just call it's Dispose
method, which is the case if you use the class System.IO.StreamWriter
(most recommended for write-only in text form):
http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx#Y0[^]. - By default, all files are opened for exclusive access. You cannot open it again until it is closed. This is the best option for most cases.
If you want to store your classes and structure, consider using
serialization instead of explicit use of files.
The best method of serialization is using
Data Contract. This approach is the most robust, non-intrusive and easiest to implement. You can store and load (restore) any arbitrary object graph in XML or JSON, even if the graph is not a tree (contains circular reference paths).
Please see:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[
^].
For more detail, please see my past answers:
How can I utilize XML File streamwriter and reader in my form application?[
^],
Creating property files...[
^],
deseralize a json string array[
^].
—SA