• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# FileStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中FileStream的典型用法代码示例。如果您正苦于以下问题:C# FileStream类的具体用法?C# FileStream怎么用?C# FileStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FileStream类属于命名空间,在下文中一共展示了FileStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: AppendResultsToFile

        public void AppendResultsToFile(String Name, double TotalTime)
        {
            FileStream file;
            file = new FileStream(Name, FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(file);

            sw.Write("***************************************\n");

            sw.Write("Total  | No Subs| %Total |%No Subs| Name\n");

            foreach (CNamedTimer NamedTimer in m_NamedTimerArray)
            {
                if (NamedTimer.GetTotalSeconds() > 0)
                {
                    String OutString;

                    OutString = String.Format("{0:0.0000}", NamedTimer.GetTotalSeconds())
                        + " | " + String.Format("{0:0.0000}", NamedTimer.GetTotalSecondsExcludingSubroutines())
                        + " | " + String.Format("{0:00.00}", System.Math.Min(99.99, NamedTimer.GetTotalSeconds() / TotalTime * 100)) + "%"
                        + " | " + String.Format("{0:00.00}", NamedTimer.GetTotalSecondsExcludingSubroutines() / TotalTime * 100) + "%"
                        + " | "
                        + NamedTimer.m_Name;

                    OutString += " (" + NamedTimer.m_Counter.ToString() + ")\n";
                    sw.Write(OutString);
                }
            }

            sw.Write("\n\n");

            sw.Close();
            file.Close();
        }
开发者ID:GeroL,项目名称:MOSA-Project,代码行数:33,代码来源:Execution+Timer.cs


示例2: Main

    static int Main()
    {
        byte [] buf = new byte [1];
        AsyncCallback ac = new AsyncCallback (async_callback);
        IAsyncResult ar;
        int sum0 = 0;

        FileStream s = new FileStream ("async_read.cs",  FileMode.Open);

        s.Position = 0;
        sum0 = 0;
        while (s.Read (buf, 0, 1) == 1)
            sum0 += buf [0];

        s.Position = 0;

        do {
            ar = s.BeginRead (buf, 0, 1, ac, buf);
        } while (s.EndRead (ar) == 1);
        sum -= buf [0];

        Thread.Sleep (100);

        s.Close ();

        Console.WriteLine ("CSUM: " + sum + " " + sum0);
        if (sum != sum0)
            return 1;

        return 0;
    }
开发者ID:robertmichaelwalsh,项目名称:CSharpFrontEnd,代码行数:31,代码来源:async_read.cs


示例3: SendFileToPrinter

	public static bool SendFileToPrinter( string szPrinterName, string szFileName )
	{
		// Open the file.
		FileStream fs = new FileStream(szFileName, FileMode.Open);
		// Create a BinaryReader on the file.
		BinaryReader br = new BinaryReader(fs);
		// Dim an array of bytes big enough to hold the file's contents.
		Byte []bytes = new Byte[fs.Length];
		bool bSuccess = false;
		// Your unmanaged pointer.
		IntPtr pUnmanagedBytes = new IntPtr(0);
		int nLength;

		nLength = Convert.ToInt32(fs.Length);
		// Read the contents of the file into the array.
		bytes = br.ReadBytes( nLength );
		// Allocate some unmanaged memory for those bytes.
		pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
		// Copy the managed byte array into the unmanaged array.
		Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
		// Send the unmanaged bytes to the printer.
		bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, nLength);
		// Free the unmanaged memory that you allocated earlier.
		Marshal.FreeCoTaskMem(pUnmanagedBytes);
		return bSuccess;
	}
开发者ID:marioricci,项目名称:erp-luma,代码行数:26,代码来源:Class2.cs


示例4: Ctor

        // This plug basically forwards all calls to the $$InnerStream$$ stream, which is supplied by the file system.

        //  public static unsafe void Ctor(String aThis, [FieldAccess(Name = "$$Storage$$")]ref Char[] aStorage, Char[] aChars, int aStartIndex, int aLength,

        public static void Ctor(FileStream aThis, string aPathname, FileMode aMode,
            [FieldAccess(Name = "$$InnerStream$$")] ref Stream innerStream)
        {
            Global.mFileSystemDebugger.SendInternal("FileStream.Ctor:");

            innerStream = InitializeStream(aPathname, aMode);
        }
开发者ID:vogon101,项目名称:Cosmos,代码行数:11,代码来源:FileStreamImpl.cs


示例5: Read

	private void Read(string filename)
	{
		XmlSerializer ser=new XmlSerializer(typeof(DataSet));
		FileStream fs=new FileStream(filename, FileMode.Open);
		DataSet ds;

		ds=(DataSet)ser.Deserialize(fs);
		fs.Close();
		
		Console.WriteLine("DataSet name: "+ds.DataSetName);
		Console.WriteLine("DataSet locale: "+ds.Locale.Name);

		foreach(DataTable t in ds.Tables) 
		{
			Console.WriteLine("Table name: "+t.TableName);
			Console.WriteLine("Table locale: "+t.Locale.Name);

			foreach(DataColumn c in t.Columns) 
			{
				Console.WriteLine("Column name: "+c.ColumnName);
				Console.WriteLine("Null allowed? "+c.AllowDBNull);
				
			}

			foreach(DataRow r in t.Rows)
			{
				Console.WriteLine("Row: "+(string)r[0]);
			}
		}
	}
开发者ID:nobled,项目名称:mono,代码行数:30,代码来源:dataset.cs


示例6: Assemble

    static void Assemble(List<string> files, string destinationDirectory)
    {
        string fileOutputPath = destinationDirectory + "assembled" + "." + matches[0].Groups[3];
        var fsSource = new FileStream(fileOutputPath, FileMode.Create);
        fsSource.Close();

        using (fsSource = new FileStream(fileOutputPath, FileMode.Append))
        {
            // reading the file paths of the parts from the files list
            foreach (var filePart in files)
            {
                using (var partSource = new FileStream(filePart, FileMode.Open))
                {
                    using (var compressionStream = new GZipStream(partSource,CompressionMode.Decompress,false))
                    {
                        // copy the bytes from part to new assembled file
                        Byte[] bytePart = new byte[4096];
                        while (true)
                        {
                            int readBytes = compressionStream.Read(bytePart, 0, bytePart.Length);
                            if (readBytes == 0)
                            {
                                break;
                            }

                            fsSource.Write(bytePart, 0, readBytes);
                        }
                    }
                }
            }
        }
    }
开发者ID:sokito,项目名称:Softuni,代码行数:32,代码来源:ZipingSlicedFiles.cs


示例7: ExportProteinSettings

    public void ExportProteinSettings()
    {
        try
        {
            CutParametersContainer exportParams = new CutParametersContainer();

            foreach (CutObject cuto in SceneManager.Get.CutObjects)
            {
                CutObjectProperties props = new CutObjectProperties();
                props.ProteinTypeParameters = cuto.IngredientCutParameters;
                props.Inverse = cuto.Inverse;
                props.CutType = (int)cuto.CutType;
                props.rotation = cuto.transform.rotation;
                props.position = cuto.transform.position;
                props.scale = cuto.transform.localScale;
                exportParams.CutObjectProps.Add(props);            
            }

            ////write
            serializer = new XmlSerializer(typeof(CutParametersContainer));
            stream = new FileStream(path, FileMode.Create);
            serializer.Serialize(stream, exportParams);
            stream.Close();
        }
        catch(Exception e)
        {
            Debug.Log("export failed: " + e.ToString());
            return;
        }

        Debug.Log("exported cutobject settings to " + path);
    }
开发者ID:jaronimoe,项目名称:cellVIEW_animated,代码行数:32,代码来源:tmp_util.cs


示例8: OnGUI

    //------------------------------------------------------------------------------------------------------------
    private void OnGUI()
    {
        m_MeshFilter = (MeshFilter)EditorGUILayout.ObjectField("MeshFilter", m_MeshFilter, typeof(MeshFilter), true);
		
		if (m_MeshFilter != null)
		{
			if (GUILayout.Button("Export OBJ"))
			{
				var lOutputPath = EditorUtility.SaveFilePanel("Save Mesh as OBJ", "", m_MeshFilter.name + ".obj", "obj");
				
				if (File.Exists(lOutputPath))
				{
					File.Delete(lOutputPath);
				}
				
				var lStream = new FileStream(lOutputPath, FileMode.Create);
				var lOBJData = m_MeshFilter.sharedMesh.EncodeOBJ();
				OBJLoader.ExportOBJ(lOBJData, lStream);
				lStream.Close();
			}
		}
		else
		{
			GUILayout.Label("Please provide a MeshFilter");
		}
    }
开发者ID:Chronovore,项目名称:armok-vision,代码行数:27,代码来源:OBJEditor.cs


示例9: Write

    public void Write(string logfilename, string log, LogType lt)
    {
#if UNITY_IPHONE || UNITY_ANDROID
        return;
#endif
        string filePathName = WriteFile(logfilename);

        FileStream fs = new FileStream(filePathName, FileMode.Append);
        StreamWriter sw = new StreamWriter(fs);
        //开始写入 
        sw.WriteLine("");
        //
        string str = "[";
        str += System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");//默认当天时间。
        str += "]";
        str += "\t";
        str += lt.ToString();
        str += "\t";
        str += log;

        sw.Write(str);
        //清空缓冲区 
        sw.Flush();
        //关闭流 
        sw.Close();
        fs.Close();
    }
开发者ID:seenen,项目名称:Tool_AssetBundles,代码行数:27,代码来源:LogFile.cs


示例10: SaveToFile

 public static void SaveToFile(Level data, string fileName)
 {
     IFormatter formatter = new BinaryFormatter();
     Stream stream = new FileStream(string.Format("{0}.level", fileName), FileMode.Create, FileAccess.Write, FileShare.Write);
     formatter.Serialize(stream, data);
     stream.Close();
 }
开发者ID:alexkirwan29,项目名称:Cubes-Of-Wrath,代码行数:7,代码来源:LevelIO.cs


示例11: Slice

 static void Slice(string destinationDirectory, int parts)
 {
     using (var sourceFile = new FileStream(destinationDirectory, FileMode.Open))
     {
     long partLength = sourceFile.Length / parts;
     long lastPartLength = (sourceFile.Length % parts) + (sourceFile.Length / parts);
     for (int i = 0; i < parts; i++)
     {
         using (var destination = new FileStream("../../Part " + (i + 1).ToString() + ".txt", FileMode.Create))
         {
             byte[] buffer;
             if (i == parts - 1)
             {
                 buffer = new byte[lastPartLength];
             }
             else
             {
                 buffer = new byte[partLength];
             }
             sourceFile.Read(buffer, 0, buffer.Length);
             destination.Write(buffer, 0, buffer.Length);
         }
     }
     }
 }
开发者ID:krasi070,项目名称:AdvancedCSharp,代码行数:25,代码来源:SlicingFile.cs


示例12: Load

    /// <summary>
    /// Loads the SessionDetails object from serialized xml SessionDetails file.
    /// </summary>
    /// <param name="serializeFileName">file Path of xml serialized SessionDetails object.</param>
    /// <returns>SessionDetails object.</returns>
    public static SessionDetails Load(string serializeFileName)
    {
        SessionDetails RetVal = null;
        FileStream _IO = null;
        if (File.Exists(serializeFileName))
        {
            try
            {
                _IO = new FileStream(serializeFileName, FileMode.Open);
                XmlSerializer _SRZFrmt = new XmlSerializer(typeof(SessionDetails));
                RetVal = (SessionDetails)_SRZFrmt.Deserialize(_IO);

            }
            catch (System.Runtime.Serialization.SerializationException ex)
            {
                Global.CreateExceptionString(ex, null);
                //throw;
            }
            finally
            {
                if (_IO != null)
                {
                    _IO.Flush();
                    _IO.Close();
                }
            }
        }

        return RetVal;
    }
开发者ID:SDRC-India,项目名称:sdrcdevinfo,代码行数:35,代码来源:SessionDetails.cs


示例13: GetPicture

 public Stream GetPicture()
 {
     string fileName = Path.Combine(HostingEnvironment.ApplicationPhysicalPath,"vista.jpg");
     FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
     System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
     return (Stream)fileStream;
 }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:7,代码来源:CountryProvinceWCFService.cs


示例14: Write

        public static void Write(FileStream aThis, byte[] aBuffer, int aOffset, int aCount,
            [FieldAccess(Name = "$$InnerStream$$")] ref Stream innerStream)
        {
            Global.mFileSystemDebugger.SendInternal("FileStream.Write:");

            innerStream.Write(aBuffer, aOffset, aCount);
        }
开发者ID:vogon101,项目名称:Cosmos,代码行数:7,代码来源:FileStreamImpl.cs


示例15: Read

        public static int Read(FileStream aThis, byte[] aBuffer, int aOffset, int aCount,
            [FieldAccess(Name = "$$InnerStream$$")] ref Stream innerStream)
        {
            Global.mFileSystemDebugger.SendInternal("FileStream.Read:");

            return innerStream.Read(aBuffer, aOffset, aCount);
        }
开发者ID:vogon101,项目名称:Cosmos,代码行数:7,代码来源:FileStreamImpl.cs


示例16: LoadName

	public static string LoadName(string path)
	{
		// The idea is to read only the number of bytes we need to determine the name of the timeline
		// We're going to exploit our knowledge of the way the unpacker works to do this - kinda hacky, but eh
		// Maybe one of these days I'll change the unpacker over to work with streams instead of byte arrays
		// Probably not
		// ...definitely not
		FileStream fs = new FileStream(path, FileMode.Open);

		// Skip over the version
		fs.Position = 4;	

		// Read the length of the string
		byte[] strLengthBytes = new byte[4];
		fs.Read(strLengthBytes, 0, 4);
		int strLength = BitConverter.ToInt32(strLengthBytes, 0);

		// Read the actual string data
		byte[] strBytes = new byte[strLength];
		fs.Read(strBytes, 0, strLength);

		// Tidy up the stream
		fs.Close();

		// Unpack and return the string
        char[] cArray = System.Text.Encoding.Unicode.GetChars(strBytes, 0, strBytes.Length);
        return new string(cArray);
	}
开发者ID:datalurkur,项目名称:HAM,代码行数:28,代码来源:HamTimeline.cs


示例17: Open

	/**
     * open file.
     * @param void.
     * @return void.
     */
	public bool Open(string strFileName, FileMode eMode, FileAccess eAccess)
	{
		if (string.IsNullOrEmpty(strFileName))
		{
			return false;
		}
		
		if ((FileMode.Open == eMode) && !File.Exists(strFileName))
		{
			return false;
		}
		
		try
		{
			m_cStream = new FileStream(strFileName, eMode, eAccess);
		}
		catch (Exception cEx)
		{
			Console.Write(cEx.Message);
		}
		
		if (null == m_cStream)
		{
			return false;
		}
		
		m_bOpen = true;
		return true;
	}
开发者ID:602147629,项目名称:2DPlatformer-SLua,代码行数:34,代码来源:YwArchiveBinFile.cs


示例18: Load

    public static bool Load(Chunk chunk)
    {

        string saveFile = SaveLocation(chunk.world.worldName);
        saveFile += FileName(chunk.pos);

        if (!File.Exists(saveFile))
            return false;
        try
        {

            IFormatter formatter = new BinaryFormatter();
            FileStream stream = new FileStream(saveFile, FileMode.Open);

            Save save = (Save)formatter.Deserialize(stream);

            //Once the blocks in the save are added they're marked as unmodified so
            //as not to trigger a new save on unload unless new blocks are added.
            for (int i =0; i< save.blocks.Length; i++)
            {
                Block placeBlock = save.blocks[i];
                placeBlock.modified = false;
                chunk.SetBlock(save.positions[i], placeBlock, false);
            }

            stream.Close();
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }


        return true;
    }
开发者ID:li5414,项目名称:Voxelmetric,代码行数:35,代码来源:Serialization.cs


示例19: WriteTo

	/// <summary>
	/// Writes the input stream to the target file.
	/// </summary>
	/// <param name="source" this="true">The source stream to write to the target file.</param>
	/// <param name="targetFile">The target file to write to.</param>
	/// <param name="append">If set to <see langword="true"/> and the file exists, then appends the source stream, otherwise, it will overwrite it.</param>
	public static void WriteTo(this Stream source, string targetFile, bool append = false)
	{
		using (var output = new FileStream(targetFile, append ? FileMode.Append : FileMode.Create))
		{
			source.WriteTo(output);
		}
	}
开发者ID:victorgarciaaprea,项目名称:xunit.vsix,代码行数:13,代码来源:StreamWriteTo.cs


示例20: Assemble

 private static void Assemble(List<string> files, string destinationDirectory)
 {
     var allData = new List<byte>();
         for (int i = 0; i < files.Count; i++)
         {
             var sourceFile = files[i];
             using (var source = new FileStream(sourceFile, FileMode.Open))
             {
                 using (var zip = new GZipStream(source, CompressionMode.Decompress))
                 {
                     byte[] buffer = new byte[4096];
                     while (true)
                     {
                         int readBytes = zip.Read(buffer, 0, buffer.Length);
                         if (readBytes == 0)
                         {
                             break;
                         }
                         for (int j = 0; j < readBytes; j++)
                         {
                             allData.Add(buffer[j]);
                         }
                     }
                 }
             }
         }
         using (var copy = new FileStream(destinationDirectory, FileMode.Create))
         {
             copy.Write(allData.ToArray(), 0, allData.Count);
         }
 }
开发者ID:PlamenaMiteva,项目名称:CSharp_Advanced,代码行数:31,代码来源:06.+Zipping+Sliced+Files.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# FileSystem类代码示例发布时间:2022-05-24
下一篇:
C# FileStatusList类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap