当前位置: 首页>>代码示例>>C#>>正文


C# FileInfo.Open方法代码示例

本文整理汇总了C#中FileInfo.Open方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.Open方法的具体用法?C# FileInfo.Open怎么用?C# FileInfo.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileInfo的用法示例。


在下文中一共展示了FileInfo.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: open

 public Stream open(string fname, FileAccess fa)
 {
     FileInfo fi = new FileInfo(di.FullName + fname);
     if(fa == FileAccess.Read)
         return fi.Open(FileMode.Open, fa, FileShare.Read);
     else
         return fi.Open(FileMode.OpenOrCreate, fa, FileShare.Read);
 }
开发者ID:Gayo,项目名称:Gayo-CAROT,代码行数:8,代码来源:Filesystem.cs

示例2: WriteTimeRefreshes

        public void WriteTimeRefreshes()
        {
            string fileName = GetTestFilePath();
            File.Create(fileName).Dispose();
            FileInfo fileInfo = new FileInfo(fileName);
            DateTime beforeWrite = DateTime.Now.AddSeconds(-1);
            using (Stream stream = new FileInfo(fileName).OpenWrite())
            {
                stream.Write(new Byte[] { 10 }, 0, 1);
            }
            DateTime afterWrite = DateTime.Now;
            fileInfo.Refresh();
            DateTime lastWriteTime = fileInfo.LastWriteTime;
            Assert.InRange<long>(fileInfo.LastWriteTime.Ticks, beforeWrite.Ticks, afterWrite.Ticks);

            //Read from the File and test the writeTime to ensure it is unchanged
            using (Stream stream = new FileInfo(fileName).OpenRead())
            {
                stream.Read(new Byte[1], 0, 1);
            }
            Assert.Equal(fileInfo.LastWriteTime, lastWriteTime);

            //Write to the file again to test lastWriteTime can be updated again
            beforeWrite = DateTime.Now.AddSeconds(-1);
            using (Stream stream = fileInfo.Open(FileMode.Open))
            {
                stream.Write(new Byte[] { 10 }, 0, 1);
            }
            afterWrite = DateTime.Now;
            Assert.Equal(fileInfo.LastWriteTime, lastWriteTime); //needs to be refreshed first
            fileInfo.Refresh();
            Assert.InRange<long>(fileInfo.LastWriteTime.Ticks, beforeWrite.Ticks, afterWrite.Ticks);
        }
开发者ID:rcabr,项目名称:corefx,代码行数:33,代码来源:get_LastWriteTime.cs

示例3: IsFileLocked

    protected static bool IsFileLocked(string fullPath)
    {
        FileInfo file = new FileInfo(fullPath);

        FileStream stream = null;

        try
        {
            stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
        }
        catch (IOException)
        {
            //the file is unavailable because it is:
            //still being written to
            //or being processed by another thread
            //or does not exist (has already been processed)
            return true;
        }
        finally
        {
            if (stream != null)
                stream.Close();
        }

        //file is not locked
        return false;
    }
开发者ID:fjkish,项目名称:DotNet,代码行数:27,代码来源:Program.cs

示例4: Load

 public void Load(FileInfo file)
 {
     if(!file.Exists) return;
     string fileData = null;
     using(FileStream fs = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
     using(StreamReader sr = new StreamReader(fs, Sjis)){
         fileData = sr.ReadToEnd();
     }
     if(string.IsNullOrEmpty(fileData)) return;
     Lines = fileData.Split(new string[]{"\x0d\x0a", "\x0a", "\x0d"}, StringSplitOptions.RemoveEmptyEntries);
 }
开发者ID:waic,项目名称:as_html_generator,代码行数:11,代码来源:TestIdListTable.cs

示例5: LoadFromHtaccess

    public static RoutingHandler LoadFromHtaccess(string defaultPage, string htaccessPath, Uri baseUri)
    {
        RoutingHandler handler = new RoutingHandler(defaultPage, baseUri);

        if (string.IsNullOrEmpty(htaccessPath)) return handler;
        FileInfo file = new FileInfo(htaccessPath);
        if (file.Exists)
        {
            HtaccessParser.Htaccess htaccess = new HtaccessParser.Htaccess(file.Open(FileMode.Open, FileAccess.Read));

            HtaccessParser.HtaccessNode rewriteEngineNode = htaccess.Find((HtaccessParser.HtaccessNode node) => { return node.Name == "RewriteEngine"; });
            if (rewriteEngineNode != null)
            {
                HtaccessParser.Directive rewriteEngineDirective = (HtaccessParser.Directive)rewriteEngineNode;
                if (rewriteEngineDirective.HasArgumentValue("on"))
                {
                    List<HtaccessParser.HtaccessNode> listRewriteRule = htaccess.FindAll((HtaccessParser.HtaccessNode node) => { return node.Name == "RewriteRule"; });
                    if (listRewriteRule != null && listRewriteRule.Count > 0)
                    {
                        foreach (HtaccessParser.Directive directive in listRewriteRule)
                        {
                            if (directive != null)
                            {
                                string[] args = directive.Arguments;
                                if (args != null && args.Length > 1)
                                {
                                    handler.SetUrlMatcher(args[0].Trim(), args[1].Trim());
                                }
                            }
                        }
                    }
                }
            }

            List<HtaccessParser.HtaccessNode> listErrorDocument = htaccess.FindAll((HtaccessParser.HtaccessNode node) => { return node.Name == "ErrorDocument"; });
            if (listErrorDocument != null)
            {
                foreach (HtaccessParser.Directive directive in listErrorDocument)
                {
                    if (directive != null)
                    {
                        string[] args = directive.Arguments;
                        if (args != null && args.Length > 1)
                        {
                            handler.SetErrorDocument(args[0].Trim(), args[1].Trim());
                        }
                    }
                }
            }
        }

        return handler;
    }
开发者ID:soeminnminn,项目名称:HtaccessParser,代码行数:53,代码来源:RoutingHandler.cs

示例6: IsFileLocked

    public static bool IsFileLocked(FileInfo file)
    {
        FileStream stream = null;

        try
        {
            stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None);
        }
        catch (IOException)
        {
            return true;
        }
        finally
        {
            if (stream != null)
            {
                stream.Close();
            }
        }

        return false;
    }
开发者ID:garciagars,项目名称:ComDriveSW,代码行数:22,代码来源:Etc.cs

示例7: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		String strValue = String.Empty;
		try
		{
			BinaryWriter dw2 = null;
			Stream fs2 = null;
			BinaryReader dr2 = null;
			FileInfo fil2 = null;		    
			MemoryStream mstr = null;
			Char ch2 = '\0';
			Char[] chArr = new Char[0];
			int ii = 0;
			String filName = s_strTFAbbrev+"Test.tmp";
			chArr = new Char[1000];
			chArr[0] = Char.MinValue;
			chArr[1] = Char.MaxValue;
			chArr[2] = '1';
			chArr[3] = 'A';
			chArr[4] = '\0';
			chArr[5] = '#';
			chArr[6] = '\t';
			for(ii = 7 ; ii < 1000 ; ii++)
				chArr[ii] = (Char)ii;
			strLoc = "Loc_8yfv7";
			fil2 = new FileInfo(filName);
			fs2 = fil2.Open(FileMode.Create);
			dw2 = new BinaryWriter(fs2);
			try {
				dw2.Write(chArr);		   
				dw2.Flush();
				fs2.Close();
				strLoc = "Loc_987hg";
				fs2 = fil2.Open(FileMode.Open);
				dr2 = new BinaryReader(fs2);
				for(ii = 0 ; ii < chArr.Length ;ii++) {
					iCountTestcases++;
					if(!(ch2 = dr2.ReadChar()).Equals(chArr[ii])) {
						iCountErrors++;
						printerr( "Error_298hg_"+ii+"! Expected=="+chArr[ii]+" , got=="+ch2);
					}
				}
				iCountTestcases++;
				try {
					ch2 = dr2.ReadChar();
					iCountErrors++;
					printerr( "Error_2389! Expected exception not thrown, ch2=="+ch2);
				} catch (EndOfStreamException) {
				} catch (Exception exc) {
					iCountErrors++;
					printerr( "Error_3298h! Unexpected exception thrown, exc=="+exc.ToString());
				}
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_278gy! Unexpected exception, exc=="+exc.ToString());
			}
			fs2.Close();
	  		fil2.Delete();
			strLoc = "Loc_98yss";
			mstr = new MemoryStream();
			dw2 = new BinaryWriter(mstr);
			try {
				dw2.Write(chArr);
				dw2.Flush();
				mstr.Position = 0;
				strLoc = "Loc_287y5";
				dr2 = new BinaryReader(mstr);
				for(ii = 0 ; ii < chArr.Length ;ii++) {
					iCountTestcases++;
					if(!(ch2 = dr2.ReadChar()).Equals(chArr[ii])) {
						iCountErrors++;
						printerr( "Error_48yf4_"+ii+"! Expected=="+chArr[ii]+" , got=="+ch2);
					}
				}
				iCountTestcases++;
				try {
					ch2 = dr2.ReadChar();
					iCountErrors++;
					printerr( "Error_2d847! Expected exception not thrown, ch2=="+ch2);
				} catch (EndOfStreamException) {
				} catch (Exception exc) {
					iCountErrors++;
					printerr( "Error_238gy! Unexpected exception thrown, exc=="+exc.ToString());
				}
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_38f85! Unexpected exception, exc=="+exc.ToString());
			}
			mstr.Close();
			strLoc = "Loc_489vy";
			mstr = new MemoryStream();
			dw2 = new BinaryWriter(mstr);
			try {
				dw2.Write((Char[])null);
				iCountErrors++;
				printerr( "Error_398ty! Expected exception not thrown");
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co5553write_carr.cs

示例8: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     String strValue = String.Empty;
     try
     {
         BinaryWriter dw2 = null;
         Stream fs2 = null;
         BinaryReader dr2 = null;
         FileInfo fil2 = null;		    
         MemoryStream mstr = null;
         String str2 = String.Empty;
         int ii = 0;
         String filName = s_strTFAbbrev+"Test.tmp";
         StringBuilder sb = new StringBuilder();
         String str1;
         for(ii = 0 ; ii < 100 ; ii++)
             sb.Append("abc");
         str1 = sb.ToString();
         strArr = new String[] {
                                   "ABC"
                                   ,"\t\t\n\n\n\0\r\r\v\v\t\0\rHello"
                                   ,"This is a normal string"
                                   ,"[email protected]#$%^&&())_+_)@#"
                                   ,"ABSDAFJPIRUETROPEWTGRUOGHJDOLJHLDHWEROTYIETYWsdifhsiudyoweurscnkjhdfusiyugjlskdjfoiwueriye"
                                   ,"     "
                                   ,"\0\0\0\t\t\tHey\"\""
                                   ,str1
                                   ,String.Empty
                               };
         if(File.Exists(filName))
             File.Delete(filName);
         strLoc = "Loc_8yfv7";
         fil2 = new FileInfo(filName);
         fs2 = fil2.Open(FileMode.Create);
         dw2 = new BinaryWriter(fs2);
         try 
         {
             for(ii = 0 ; ii < strArr.Length ; ii++)
                 dw2.Write(strArr[ii]);		   
             dw2.Flush();
             fs2.Close();
             strLoc = "Loc_987hg";
             fs2 = fil2.Open(FileMode.Open);
             dr2 = new BinaryReader(fs2);
             for(ii = 0 ; ii < strArr.Length ;ii++) 
             {
                 iCountTestcases++;
                 if(!(str2 = dr2.ReadString()).Equals(strArr[ii])) 
                 {
                     iCountErrors++;
                     printerr( "Error_298hg_"+ii+"! Expected=="+strArr[ii]+" , got=="+str2);
                 }
             }
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_278gy_"+ii+"! Unexpected exception, exc=="+exc.ToString());
         }
         fs2.Close();
         fil2.Delete();
         strLoc = "Loc_98yss";
         mstr = new MemoryStream();
         dw2 = new BinaryWriter(mstr);
         try 
         {
             for(ii = 0 ; ii < strArr.Length ; ii++) 
                 dw2.Write(strArr[ii]);
             dw2.Flush();
             mstr.Position = 0;
             strLoc = "Loc_287y5";
             dr2 = new BinaryReader(mstr);
             for(ii = 0 ; ii < strArr.Length ;ii++) 
             {
                 iCountTestcases++;
                 if(!(str2 = dr2.ReadString()).Equals(strArr[ii])) 
                 {
                     iCountErrors++;
                     printerr( "Error_48yf4_"+ii+"! Expected=="+strArr[ii]+" , got=="+str2);
                 }
             }
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_38f85_"+ii+"! Unexpected exception, exc=="+exc.ToString());
         }
         mstr.Close();
         strLoc = "Loc_489vy";
         mstr = new MemoryStream();
         dw2 = new BinaryWriter(mstr);
         try 
         {
             dw2.Write((String)null);
             iCountErrors++;
             printerr( "Error_398ty! Expected exception not thrown");
         } 
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co5651readstring.cs

示例9: LoadConfigurations

    void LoadConfigurations()
    {
        string scriptAssetPath = AssetDatabase.GetAssetPath(scriptAsset);
        int lastSlashIndex = scriptAssetPath.LastIndexOf('/');
        if(lastSlashIndex == -1) {
            lastSlashIndex = scriptAssetPath.LastIndexOf('\\');
        }
        scriptAssetPath = scriptAssetPath.Substring(0, lastSlashIndex + 1);

        string projectPath = Application.dataPath;
        lastSlashIndex = projectPath.LastIndexOf('/');
        if(lastSlashIndex == -1) {
            lastSlashIndex = projectPath.LastIndexOf('\\');
        }
        projectPath = projectPath.Substring(0, lastSlashIndex + 1);;

        string assetSettingsFilePath = projectPath + scriptAssetPath + "AssetSettings.xml";
        assetConfigFile = new FileInfo(assetSettingsFilePath);

        configurations = new List<AssetConfiguration>();

        StreamReader reader = new StreamReader(assetConfigFile.Open(FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read));

        string line = string.Empty;
        while((line = reader.ReadLine()) != null) {
            if(line.Contains(VerySimpleXml.StartNode(AssetConfiguration.nodeName)))
                configurations.Add(new AssetConfiguration(reader));
        }

        reader.Close();
    }
开发者ID:azanium,项目名称:TruthNIslam-Unity,代码行数:31,代码来源:AssetSettingsWindow.cs

示例10: GetFileLines

 protected static string[] GetFileLines(FileInfo file)
 {
     if(!file.Exists) return new string[0];
     string fileData = null;
     using(FileStream fs = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
     using(StreamReader sr = new StreamReader(fs, Sjis)){
         fileData = sr.ReadToEnd();
     }
     if(string.IsNullOrEmpty(fileData)) return new string[0];
     string[] result = fileData.Split(new string[]{"\x0d\x0a", "\x0a", "\x0d"}, StringSplitOptions.RemoveEmptyEntries);
     return result;
 }
开发者ID:waic,项目名称:as_html_generator,代码行数:12,代码来源:CsvDataTable.cs

示例11: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		String strValue = String.Empty;
		try
		{
			BinaryWriter dw2 = null;
			Stream fs2 = null;
			BinaryReader dr2 = null;
			FileInfo fil2 = null;
			strLoc = "Loc_98hg8";
			iCountTestcases++;
			try {
				dw2 = new BinaryWriter(null);
				iCountErrors++;
				printerr( "Error_1099x! Expected exception not thrown");
			} catch (ArgumentNullException) {
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_1908v! Incorrect exception thrown, exc=="+exc.ToString());
			}
			strLoc = "Loc_g87vj";
			fil2 = new FileInfo("TestFile.tmp");
			iCountTestcases++;
			try {
			fs2 = fil2.Open(FileMode.Create, FileAccess.Read);
				dw2 = new BinaryWriter(fs2);
				iCountErrors++;
				printerr( "Error_1y8g7! Expected exception not thrown");
				fs2.Close();
			} catch (ArgumentException) {
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_198yx! Incorrect Exception thrown, exc=="+exc.ToString());
			} 
			new FileInfo("TestFile.tmp").Delete();
			strLoc = "Loc_785hv";
			fil2 = new FileInfo("TestFile.tmp");
			fs2 = fil2.Open(FileMode.Create, FileAccess.Write);
			dw2 = new BinaryWriter(fs2);
			dw2.Write(true);
			dw2.Flush();
			fs2.Close();
			strLoc = "Loc_987hg";
			fs2 = fil2.Open(FileMode.Open);
			dr2 = new BinaryReader(fs2);
			iCountTestcases++;
			if(!dr2.ReadBoolean()) {
				iCountErrors++;
				printerr("Error_287gy! Correct value not written");
			}
			fs2.Close();
			fil2.Delete();
			strLoc = "Loc_98yvh";
			MemoryStream mstr = new MemoryStream();
			dw2 = new BinaryWriter(mstr);
			dw2.Write(true);
			dw2.Flush();
			mstr.Position = 0;
			dr2 = new BinaryReader(mstr);
			iCountTestcases++;
			if(!dr2.ReadBoolean()) {
				iCountErrors++;
				printerr( "Error_298yx! Incorrect value on stream");
			}
			dr2.Close();
			strLoc = "Loc_09u95";
			mstr = new MemoryStream();
			mstr.Close();
			iCountTestcases++;
			try {
				dw2 = new BinaryWriter(mstr);
				iCountErrors++;
				printerr( "Error_98t4y! Expected exception not thrown");
			} catch ( ArgumentException) {
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_092xc! Incorrect exception thrown, exc=="+exc.ToString());
			}
		} catch (Exception exc_general ) {
			++iCountErrors;
			Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
		}
		if ( iCountErrors == 0 )
		{
			Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
			return true;
		}
		else
		{
			Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
			return false;
		}
	}
开发者ID:ArildF,项目名称:masters,代码行数:97,代码来源:co5536ctor_str.cs

示例12: Start

    void Start()
    {
        dirRoot = Directory.GetCurrentDirectory() + @"\" + TEXTURE;

        bgRoot = dirRoot + BG_PATH;
        enemyRoot = dirRoot + ENEMY_PATH;

        if (!Directory.Exists(dirRoot)) {
            Directory.CreateDirectory(dirRoot);

            if (!Directory.Exists(bgRoot)) {
                Directory.CreateDirectory(bgRoot);
            }

            if (!Directory.Exists(enemyRoot)) {
                Directory.CreateDirectory(enemyRoot);
            }
        }

        FileInfo file = new FileInfo(dirRoot + SPEED_DATA_FILE_NAME);
        using (FileStream fs = file.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite))
        using (StreamReader sr = new StreamReader(fs)) {
            speedFileDataStr = sr.ReadToEnd();
        }

        setBGTextureList();
        setEnemyTextureList();
    }
开发者ID:RegalStranger,项目名称:shootingGame,代码行数:28,代码来源:TextureDebug.cs

示例13: runTest

    public static void runTest()
    {
        String strLoc = "Loc_000oo";
        String strValue = String.Empty;
        int iCountErrors = 0;
        int iCountTestcases = 0;

        try
        {
            /////////////////////////  START TESTS ////////////////////////////
            ///////////////////////////////////////////////////////////////////


            String filName = Path.Combine(TestInfo.CurrentDirectory, Path.GetRandomFileName());
            FileInfo fil2;
            Stream stream;


            if (File.Exists(filName))
                File.Delete(filName);



            // [] Exception for null string
            //-----------------------------------------------------------

            // [] Create a directory and check the creation time

            strLoc = "Loc_r8r7j";

            new FileStream(filName, FileMode.Create).Dispose();
            fil2 = new FileInfo(filName);
            stream = fil2.OpenWrite();
            stream.Write(new Byte[] { 10 }, 0, 1);
            stream.Dispose();
            Task.Delay(4000).Wait();
            fil2.Refresh();
            iCountTestcases++;
            DateTime lastWriteTime = fil2.LastWriteTime;
            if ((DateTime.Now - lastWriteTime).TotalMilliseconds < 2000 ||
               (DateTime.Now - lastWriteTime).TotalMilliseconds > 5000)
            {
                iCountErrors++;
                Console.WriteLine(lastWriteTime);
                Console.WriteLine((DateTime.Now - lastWriteTime).TotalMilliseconds);
                printerr("Error_20hjx! Last Write Time time cannot be correct");
            }


            // [] 

            strLoc = "Loc_20yxc";

            stream = fil2.Open(FileMode.Open, FileAccess.Read);
            stream.Read(new Byte[1], 0, 1);
            stream.Dispose();
            fil2.Refresh();
            if (fil2.LastWriteTime != lastWriteTime)
            {
                iCountErrors++;
                printerr("Eror_209x9! LastWriteTime should not have changed due to a read");
            }

            stream = fil2.Open(FileMode.Open);
            stream.Write(new Byte[] { 10 }, 0, 1);
            stream.Dispose();
            Task.Delay(3000).Wait();
            fil2.Refresh();
            iCountTestcases++;
            if ((DateTime.Now - fil2.LastWriteTime).TotalMilliseconds < 1000 ||
               (DateTime.Now - fil2.LastWriteTime).TotalMilliseconds > 5000)
            {
                iCountErrors++;
                Console.WriteLine((DateTime.Now - fil2.LastWriteTime).TotalMilliseconds);
                printerr("Eror_f984f! LastWriteTime is way off");
            }




            //-----------------------------------------------------------


            if (File.Exists(filName))
                File.Delete(filName);

            ///////////////////////////////////////////////////////////////////
            /////////////////////////// END TESTS /////////////////////////////
        }
        catch (Exception exc_general)
        {
            ++iCountErrors;
            Console.WriteLine("Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==" + exc_general.ToString());
        }
        ////  Finish Diagnostics
        if (iCountErrors != 0)
        {
            Console.WriteLine("FAiL! " + s_strTFName + " ,iCountErrors==" + iCountErrors.ToString());
        }

//.........这里部分代码省略.........
开发者ID:johnhhm,项目名称:corefx,代码行数:101,代码来源:get_LastWriteTime.cs

示例14: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     String strValue = String.Empty;
     try
     {			
         BinaryWriter dw2 = null;
         Stream fs2 = null;
         BinaryReader dr2 = null;
         FileInfo fil2 = null;		    
         MemoryStream mstr = null;
         SByte sbyt2 = 0;
         int ii = 0;
         String filName = s_strTFAbbrev+"Test.tmp";
         if(File.Exists(filName))
             File.Delete(filName);
         strLoc = "Loc_8yfv7";
         fil2 = new FileInfo(filName);
         fs2 = fil2.Open(FileMode.Create);
         dw2 = new BinaryWriter(fs2);
         try 
         {
             for(ii = 0 ; ii < sbArr.Length ; ii++)
                 dw2.Write(sbArr[ii]);		   
             dw2.Flush();
             fs2.Close();
             strLoc = "Loc_987hg";
             fs2 = fil2.Open(FileMode.Open);
             dr2 = new BinaryReader(fs2);
             for(ii = 0 ; ii < sbArr.Length ;ii++) 
             {
                 iCountTestcases++;
                 if((sbyt2 = dr2.ReadSByte()) != sbArr[ii]) 
                 {
                     iCountErrors++;
                     printerr( "Error_298hg_"+ii+"! Expected=="+sbArr[ii]+" , got=="+sbyt2);
                 }
             }
             iCountTestcases++;
             try 
             {
                 sbyt2 = dr2.ReadSByte();
                 iCountErrors++;
                 printerr( "Error_2389! Expected exception not thrown, sbyt2=="+sbyt2);
             } 
             catch (EndOfStreamException) 
             {
             } 
             catch (Exception exc) 
             {
                 iCountErrors++;
                 printerr( "Error_3298h! Unexpected exception thrown, exc=="+exc.ToString());
             }
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_278gy! Unexpected exception, exc=="+exc.ToString());
         }
         fs2.Close();
         fil2.Delete();
         strLoc = "Loc_98yss";
         mstr = new MemoryStream();
         dw2 = new BinaryWriter(mstr);
         try 
         {
             for(ii = 0 ; ii < sbArr.Length ; ii++) 
                 dw2.Write(sbArr[ii]);
             dw2.Flush();
             mstr.Position = 0;
             strLoc = "Loc_287y5";
             dr2 = new BinaryReader(mstr);
             for(ii = 0 ; ii < sbArr.Length ;ii++) 
             {
                 iCountTestcases++;
                 if((sbyt2 = dr2.ReadSByte()) != sbArr[ii]) 
                 {
                     iCountErrors++;
                     printerr( "Error_48yf4_"+ii+"! Expected=="+sbArr[ii]+" , got=="+sbyt2);
                 }
             }
             iCountTestcases++;
             try 
             {
                 sbyt2 = dr2.ReadSByte();
                 iCountErrors++;
                 printerr( "Error_2d847! Expected exception not thrown, sbyt2=="+sbyt2);
             } 
             catch (EndOfStreamException) 
             {
             } 
             catch (Exception exc) 
             {
                 iCountErrors++;
                 printerr( "Error_238gy! Unexpected exception thrown, exc=="+exc.ToString());
             }
         } 
         catch (Exception exc) 
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co5650readsbyte.cs

示例15: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		String strValue = String.Empty;
		try
		{
			BinaryWriter dw2 = null;
			Stream fs2 = null;
			BinaryReader dr2 = null;
			FileInfo fil2 = null;		    
			MemoryStream mstr = null;
			Char ch2 = '\0';
			Char[] chArr = new Char[0];
			int ii = 0;
			strLoc = "Loc_8yfv7";
			fil2 = new FileInfo("TestFile.tmp");
			fs2 = fil2.Open(FileMode.Create);
			dw2 = new BinaryWriter(fs2);
			try {
			chArr = new Char[]{'A', '8', '*', '\0', '\u2917', '%', '#', '<', '\n', '\t', '>'};
			for(ii = 0 ; ii < chArr.Length ; ii++) {
				Console.WriteLine("Writing: "+chArr[ii]);
				dw2.Write(chArr[ii]);			
			}
			dw2.Flush();
			fs2.Close();			
			strLoc = "Loc_987hg";
			fs2 = fil2.Open(FileMode.Open);
			dr2 = new BinaryReader(fs2);
			try {
				for(ii = 0 ; ;ii++) {
					iCountTestcases++;
					Console.WriteLine(ii);			   
					if((ch2 = dr2.ReadChar()) != chArr[ii]) {
						iCountErrors++;
						printerr( "Error_298hg! Expected=="+chArr[ii]+" , got=="+ch2);
					}
					Console.WriteLine(ch2);
				}
			} catch (EndOfStreamException) {
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_3298h! Unexpected exception thrown, exc=="+exc.ToString());
			}
			iCountTestcases++;
			if(ii != chArr.Length) {
				iCountErrors++;
				printerr( "Error_2g767! Incorrect number of elements on filestream");
			}
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_278gy! Unexpected exception, exc=="+exc.ToString());
			}
			fs2.Close();
			fil2.Delete();
			strLoc = "Loc_98yss";
			mstr = new MemoryStream();
			dw2 = new BinaryWriter(mstr);
			try {
			chArr = new Char[]{'A', 'c', '\0', '\u2701', '$', '.', '1', 'l', '\u00FF', '\n', '\t', '\v' };
			for(ii = 0 ; ii < chArr.Length ; ii++) 
				dw2.Write(chArr[ii]);
			dw2.Flush();
			mstr.Position = 0;
			strLoc = "Loc_287y5";
			dr2 = new BinaryReader(mstr);
			try {
				for(ii = 0 ; ; ii++) {
					iCountTestcases++;			
					Console.WriteLine(ii);
					if((ch2 = dr2.ReadChar()) != chArr[ii]) {
						iCountErrors++;
						printerr( "Error_948yg! Expected=="+chArr[ii]+", got=="+ch2);
					} 
				} 
			} catch (EndOfStreamException) {
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_238gy! Unexpected exception thrown, exc=="+exc.ToString());
			}
			iCountTestcases++;
			if(ii != chArr.Length) {
				iCountErrors++;
				printerr( "Error_289yg! Incorrect number of elements in filestream");
			}
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_298gy! Unexpected exception, exc=="+exc.ToString());
			}
			mstr.Close();
		} catch (Exception exc_general ) {
			++iCountErrors;
			Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
		}
		if ( iCountErrors == 0 )
		{
			Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co5538write_char.cs


注:本文中的FileInfo.Open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。