use Path object to determine path integrity and correctness
Using system;using system.io;class Test {public static void Main () {String path1 = @ "C:\temp\MyTest.txt"; String path2 = @ "C:\temp\MyTest"; String path3 = @ "Temp"; if (Path.hasextension (path1)) {Console.WriteLine ("{0} have an extension.", path1); } if (! Path.hasextension (path2)) {Console.WriteLine ("{0} has no extension.", path2); } if (! Path.ispathrooted (Path3)) {Console.WriteLine ("The string {0} contains no root information.", PATH3); } Console.WriteLine ("The full path of {0} is {1}.", Path3, Path.GetFullPath (path3)); Console.WriteLine ("{0} is the location for temporary files.", Path.gettemppath ()); Console.WriteLine ("{0} is a file available for use.", Path.gettempfilename ()); /* This code produces output similar to the following: * c:\temp\MyTest.txt have an extension. * C:\temp\MyTest has no extension. * The string temp contains no root information. * The full path of temp is D:\Documents and Settings\cliffc\my documents\visual Studio 2005\projects\consoleapplication2\c Onsoleapplication2\bin\debug\temp. * D:\Documents and Settings\cliffc\local settings\temp\8\ are the location for temporary files. * D:\Documents and Settings\cliffc\local settings\temp\8\tmp3d.tmp is a file available for use. */ }}
Create a file with FileInfo
Using system;using system.io;class Test {public static void Main () {//Gets the cache path through the path object string path = Path.gettempfilename (); FileInfo fi1 = new FileInfo (path); Creates a file and writes the data using a "file stream write Object" (StreamWriter SW = fi1). CreateText ()) {SW. WriteLine ("Hello"); Sw. WriteLine ("and"); Sw. WriteLine ("Welcome"); }//Opens the file and reads the data using (StreamReader sr = fi1) by returning the "file stream read Object". OpenText ()) {string s = ""; while (s = Sr. ReadLine ()) = null) {Console.WriteLine (s); }} try {string path2 = Path.gettempfilename (); FileInfo fi2 = new FileInfo (path2); Delete File Fi2. Delete (); Copy the F1 file to the F2 file FI1. CopyTo (path2); Console.WriteLine ("{0} is copied to {1}.", Path, path2); Delete File Fi2. Delete (); Console.WriteLine ("{0} wasSuccessfully deleted. ", path2); } catch (Exception e) {Console.WriteLine ("The process failed: {0}", e.tostring ()); } }}
File Storage Management in Unity3d