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


C# FileInfo.OpenRead方法代码示例

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


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

示例1: Decompress

    public static void Decompress(FileInfo fi)
    {
        // Get the stream of the source file.
        using (FileStream inFile = fi.OpenRead())
        {
            // Get original file extension,
            // for example "doc" from report.doc.cmp.
            string curFile = fi.FullName;
            string origName = curFile.Remove(curFile.Length
                    - fi.Extension.Length);

            //Create the decompressed file.
            using (FileStream outFile = File.Create(origName))
            {
                using (DeflateStream Decompress = new DeflateStream(inFile,
                    CompressionMode.Decompress))
                {
                    // Copy the decompression stream
                    // into the output file.
                    Decompress.CopyTo(outFile);

                    Console.WriteLine("Decompressed: {0}", fi.Name);
                }
            }
        }
    }
开发者ID:SebsCodeVault,项目名称:DeflateStream,代码行数:26,代码来源:Program.cs

示例2: Decompress

            public static void Decompress(FileInfo archFile, out String szOutFile)
            {
                Logger.Enter();
                using (FileStream archFileStream = archFile.OpenRead())
                {
                    String currentFileName = archFile.FullName;
                    String newFileName = currentFileName.Remove(
                        currentFileName.Length - archFile.Extension.Length);

                    using (FileStream normalFileStream = File.Create(newFileName))
                    {
                        using (GZipStream decompressionStream = new GZipStream(archFileStream, CompressionMode.Decompress))
                        {
                            byte[] buffer = new byte[1024];
                            int nRead;
                            while ((nRead = decompressionStream.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                normalFileStream.Write(buffer, 0, nRead);
                            }

                            szOutFile = newFileName;
                            Console.WriteLine("Decompressed: {0}", archFile.Name);
                        }
                    }
                }
                Logger.Leave();
            }
开发者ID:AndrianDTR,项目名称:Atlantic,代码行数:27,代码来源:Packer.cs

示例3: Compress

    public static void Compress(FileInfo fi)
    {
        // Get the stream of the source file.
        using (FileStream inFile = fi.OpenRead())
        {
            // Prevent compressing hidden and already compressed files.
            if ((File.GetAttributes(fi.FullName) & FileAttributes.Hidden)
                != FileAttributes.Hidden & fi.Extension != ".cmp")
            {
                // Create the compressed file.
                using (FileStream outFile =
                        File.Create(fi.FullName + ".cmp"))
                {
                    using (DeflateStream Compress =
                        new DeflateStream(outFile,
                        CompressionMode.Compress))
                    {
                        // Copy the source file into
                        // the compression stream.
                        inFile.CopyTo(Compress);

                        Console.WriteLine("Compressed {0} from {1} to {2} bytes.",
                        fi.Name, fi.Length.ToString(), outFile.Length.ToString());
                    }
                }
            }
        }
    }
开发者ID:SebsCodeVault,项目名称:DeflateStream,代码行数:28,代码来源:Program.cs

示例4: ReadFile

 private void ReadFile()
 {
     FileInfo fi = new FileInfo(Application.dataPath + "/Data/Data.txt");
     if (fi == null) return;
     StreamReader sr = new StreamReader(fi.OpenRead(), Encoding.UTF8);
     _path = sr.ReadToEnd();
 }
开发者ID:satoaki131,项目名称:SlidePuzzle,代码行数:7,代码来源:DataStream.cs

示例5: getBinaryFromFile

 public static byte[] getBinaryFromFile(FileInfo f)
 {
     byte[] buffer = null;
     if (f.Exists)
     {
       try
       {
     buffer = new byte[f.OpenRead().Length];
     f.OpenRead().Read(buffer, 0, (int)f.OpenRead().Length);
       }
       catch (Exception ex)
       {
     LoggerFacade.Log(ex);
       }
     }
     return buffer;
 }
开发者ID:royriojas,项目名称:RGEN2,代码行数:17,代码来源:vEstadisticas.aspx.cs

示例6: FileAccessTest

 public static int FileAccessTest (String file_name)
  {
    FileInfo fi = new FileInfo (file_name);
    FileStream fs = fi.OpenRead ();
    Console.WriteLine (fi.Length);
    Byte [] bt = new byte [fi.Length];
    return fs.Read (bt, 0, (int) fi.Length);
  }
开发者ID:jplu,项目名称:virtuoso-opensource,代码行数:8,代码来源:unrestricted.cs

示例7: ReadcsvString

    static string ReadcsvString()
    {
        FileInfo fi = new FileInfo(Application.dataPath + "/Resources/EnemySpoawn.csv");
        using (StreamReader sr = new StreamReader(fi.OpenRead(), Encoding.UTF8)) {
            return sr.ReadToEnd();

        }
    }
开发者ID:mban259,项目名称:STG,代码行数:8,代码来源:Read.cs

示例8: read

 // 読み込み
 public void read()
 {
     FileInfo fi = new FileInfo(Application.dataPath+"/test.txt");
     StreamReader sr = new StreamReader(fi.OpenRead());
     while( sr.Peek() != -1 ){
         print( sr.ReadLine() );
         }
        sr.Close();
 }
开发者ID:nosaj0926,项目名称:4takuhakase,代码行数:10,代码来源:data_backup.cs

示例9: read

    // テキストの読み込み
    public void read()
    {
        FileInfo fi = new FileInfo(Application.dataPath + "/" + filepath);
        StreamReader sr = new StreamReader(fi.OpenRead());

        int i = 0;
        while (sr.Peek() != -1)
        {
            scenarios[i] = sr.ReadLine();
            i++;
        }
        i = 0;
        sr.Close();
    }
开发者ID:RewindAlice,项目名称:RewindAlice,代码行数:15,代码来源:ChangeCharacter.cs

示例10: _readFile

 //    データ読み込
 void _readFile()
 {
     // FileReadTest.txtファイルを読み込む
     FileInfo fi = new FileInfo(Application.dataPath + "/" + "data.csv");
     try {
         // 一行毎読み込み
         using (StreamReader sr = new StreamReader(fi.OpenRead(), Encoding.UTF8)){
             guitxt = sr.ReadToEnd();
         }
     } catch (Exception /* e */ ){
         // 改行コード
         guitxt += SetDefaultText();
     }
 }
开发者ID:pepeta,项目名称:HorSagaReplay,代码行数:15,代码来源:BattleMain.cs

示例11: ReadFile

    //--------------------
    // ファイル読み込み
    //--------------------
    string ReadFile( string fileName )
    {
        string strTemp = "";
        FileInfo fi = new FileInfo( Application.dataPath + fileName );
        try {
            using( StreamReader sr = new StreamReader(fi.OpenRead(), Encoding.UTF8) ) {
                strTemp = sr.ReadToEnd();
            }
        } catch (Exception e){
            Debug.LogException ( e );
            strTemp = "";
        }

        return( strTemp );
    }
开发者ID:ktakayanagi,项目名称:DataTest,代码行数:18,代码来源:DataTest.cs

示例12: ReadJSON

 public static SimpleJSON.JSONNode ReadJSON(string path)
 {
     var fullPath = Path.Combine(Application.streamingAssetsPath, path);
     var fileInfo = new FileInfo(fullPath);
     using ( var stream = new StreamReader(fileInfo.OpenRead(), System.Text.Encoding.UTF8) ) {
         try {
             var jsonStr = stream.ReadToEnd();
             var json = SimpleJSON.JSON.Parse(jsonStr);
             return json;
         } catch (System.Exception e) {
             Debug.LogError(e.StackTrace);
         }
     }
     return null;
 }
开发者ID:AlexanderMazaletskiy,项目名称:unity-lego-game,代码行数:15,代码来源:ReadJSON.cs

示例13: Main

 public static void Main(string[] args)
 {
     FileInfo fl = new FileInfo(@"..\..\ReadBinary.txt");
     Stream strm = fl.OpenRead();
     int iNext;
     do
     {
        iNext = strm.ReadByte();
        if (iNext != -1)
           Console.WriteLine(iNext.ToString());
     }
     while (iNext != -1);
     strm.Close();
     Console.WriteLine("All done.");
     Console.ReadLine();
 }
开发者ID:Nagato23,项目名称:CsBasic,代码行数:16,代码来源:ReadBinary.cs

示例14: ReadFileString

	// ファイルを読み込んで内容を文字列で戻す.
	public static string ReadFileString(string path)
	{
		string s;
#if !UNITY_WEBPLAYER

		FileInfo fi = new FileInfo(Application.dataPath + "/" + path);
		using (StreamReader sr = new StreamReader(fi.OpenRead(), Encoding.UTF8))
		{
			s = sr.ReadToEnd();
		}

#else
		Debug.LogError("WebPlayerではOpenReadは使えません.");
#endif
		return s;
	}
开发者ID:okuhiiro,项目名称:UnityInitProject,代码行数:17,代码来源:FileWorker.cs

示例15: Main

	public static void Main (string [] args)
	{
		if (args.Length == 0 || args.Length > 3) {
			Console.WriteLine ("Usage: zipmark FILE [ITERATIONS] [BLOCKSIZE]");
			return;
		}
	
		string filename = args [0];
		FileInfo file = new FileInfo (filename);
		if (!file.Exists) {
			Console.WriteLine ("Couldn't find file {0}", filename);
			return;
		}

		FileStream fs = file.OpenRead ();

		byte [] raw = new byte [file.Length];
		int count = fs.Read (raw, 0, (int)file.Length);
		fs.Close ();

		if (count != file.Length) {
			Console.WriteLine ("Couldn't read file {0}", filename);
			return;
		}

		Deflater def = new Deflater (Deflater.BEST_COMPRESSION, false);
		Inflater inf = new Inflater (false);

		// 1. Count deflated size

		int cooked_size = Deflate (def, raw, null);
		byte [] cooked = new byte [cooked_size];

		// 2. Deflate & Inflate

		if (args.Length > 1)
			Iterations = Int32.Parse (args [1]);
		if (args.Length > 2)
			BlockSize = Int32.Parse (args [2]);

		for (int i = 0; i < Iterations; ++ i) {
			Deflate (def, raw, cooked);
			Inflate (inf, cooked, raw);
		}

		return;
	}
开发者ID:Zman0169,项目名称:mono,代码行数:47,代码来源:zipmark.cs


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