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


C# FileStream.Dispose方法代码示例

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


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

示例1: GetExistAccessToken

 /// 获取token,如果存在且没过期,则直接取token
 /// <summary>
 /// 获取token,如果存在且没过期,则直接取token
 /// </summary>
 /// <returns></returns>
 public static string GetExistAccessToken()
 {
     // 读取XML文件中的数据
     string filepath = System.Web.HttpContext.Current.Server.MapPath("/XMLToken.xml");
     FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     StreamReader str = new StreamReader(fs, System.Text.Encoding.UTF8);
     XmlDocument xml = new XmlDocument();
     xml.Load(str);
     str.Close();
     str.Dispose();
     fs.Close();
     fs.Dispose();
     string Token = xml.SelectSingleNode("xml").SelectSingleNode("AccessToken").InnerText;
     DateTime AccessTokenExpires = Convert.ToDateTime(xml.SelectSingleNode("xml").SelectSingleNode("AccessExpires").InnerText);
     //如果token过期,则重新获取token
     if (DateTime.Now >= AccessTokenExpires)
     {
         AccessToken mode = Getaccess();
         //将token存到xml文件中,全局缓存
         xml.SelectSingleNode("xml").SelectSingleNode("AccessToken").InnerText = mode.access_token;
         DateTime _AccessTokenExpires = DateTime.Now.AddSeconds(mode.expires_in);
         xml.SelectSingleNode("xml").SelectSingleNode("AccessExpires").InnerText = _AccessTokenExpires.ToString();
         xml.Save(filepath);
         Token = mode.access_token;
     }
     return Token;
 }
开发者ID:shinygang,项目名称:Wechat-JSSDK,代码行数:32,代码来源:JSSDK.cs

示例2: IpHelper

        private static long _indexcount;//索引个数

        static IpHelper() {
            string filePath = Common.GetMapPath("/App_Data/Site/ipdata.config");
            if (File.Exists(filePath)) {
                try {
                    _ipdatefile = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                }
                catch {
                    _ipdatefile.Close();
                    _ipdatefile.Dispose();
                    return;
                }
                _ipdatefile.Position = 0;
                _indexareabegin = ReadByte4();
                _indexareaend = ReadByte4();
                _indexcount = (_indexareaend - _indexareabegin) / LENGTH + 1;

                if (_indexcount > 0) {
                    _state = true;
                }
                else {
                    _ipdatefile.Close();
                    _ipdatefile.Dispose();
                }
            }
        }
开发者ID:PerryPal,项目名称:AuthoryManage,代码行数:27,代码来源:IpHelper.cs

示例3: PutImageToCache

        public bool PutImageToCache(MemoryStream tile, MapType type, Point pos, int zoom)
        {
            FileStream fs = null;
            try
            {
                string fileName = GetFilename(type, pos, zoom, true);
                fs = new FileStream(fileName, FileMode.Create);
                tile.WriteTo(fs);
                tile.Flush();
                fs.Close();
                fs.Dispose();
                tile.Seek(0, SeekOrigin.Begin);

                return true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Error in FilePureImageCache.PutImageToCache:\r\n" + ex.ToString());
                if (fs != null)
                {
                    fs.Close();
                    fs.Dispose();
                }
                return false;
            }
        }
开发者ID:deb761,项目名称:BikeMap,代码行数:26,代码来源:FilePureImageCache.cs

示例4: HandlesMultipleDispose

 public void HandlesMultipleDispose()
 {
     using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create))
     {
         fs.Dispose();
         fs.Dispose();
     }  // disposed as we leave using
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:8,代码来源:Dispose.cs

示例5: XmlDocument

        /*
         * Function: ReadFile
         * Description:XMLStrategy算法读取函数
         * Parameters:
         *      string sPath 文件路径
         *      StyleSet pStyle 绘制样式集
         * Return Value:cNet
         */
        cNet IfIOStrategy.ReadFile(string sPath)
        {
            FileStream stream = null;
            XmlDocument doc = new XmlDocument();
            XmlNodeList Nodelist;
            XmlNode xmlroot, xmltmp;
            cNet NewNet;
            int iNum;

            try
            {
                stream = new FileStream(sPath, FileMode.Open);
                doc.Load(stream);               //从流文件读入xml文档
                stream.Close();
            }
            catch (Exception ex)
            {
                if (stream != null)
                {
                    ex.ToString();
                    stream.Dispose();
                }
                return null;
            }
            stream.Dispose();
            xmlroot = doc.ChildNodes.Item(0);
            Nodelist = xmlroot.ChildNodes;                                             //获取节点列表
            xmltmp = Nodelist[0].ChildNodes[3];
            //创建网络
            NewNet = new cNet(Nodelist.Count);
            for (iNum = 0; iNum < Nodelist.Count; iNum++)
            {
                switch (xmltmp.Name)
                {//区分XML数据类型
                    case "Word"://如果包含Word标签,就是关键词网络文件,生成KNode
                        NewNet.Network.Add(new kNode(iNum));
                        break;
                    default://默认都是cNode
                        NewNet.Network.Add(new cNode(iNum));
                        break;
                } 
            }
            NewNet.XMLtoNet(doc);
            if (NewNet.intNumber == 0)
            {
                return null;
            }
            return NewNet;
        }
开发者ID:Dainter,项目名称:CNSP-Preussen,代码行数:57,代码来源:XMLStrategy.cs

示例6: learnFormAssetBundle

 private void learnFormAssetBundle(string path)
 {
     FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
     DataReader br = new DataReader(fs);
     SerializeBundle bundle = new SerializeBundle();
     bundle.DeSerialize(br);
     foreach (var bundleEntry in bundle.entrys) {
         int version = AssetToolUtility.GetAssetsFileVersion(bundleEntry.assetData);
         var serializeAssets = SerializeAssetFactory.CreateWithVersion(version);
         if (serializeAssets != null) {
             MemoryStream ms = new MemoryStream(bundleEntry.assetData);
             DataReader dr = new DataReader(ms);
             serializeAssets.DeSerialize(dr);
             var assetTypeTreeDB = AssetToolUtility.GenerateTypeTreeDataBase(serializeAssets);
             if (assetTypeTreeDB != null) {
                 var allType = assetTypeTreeDB.GetAllType(version);
                 foreach (var type in allType) {
                     Console.WriteLine("AddType:Version:{0},ClassID{1},Name:{2}", version, type.Key, type.Value.type);
                 }
             }
             typeTreeDatabase = assetTypeTreeDB.Merage(typeTreeDatabase);
         } else {
             Debug.LogError("can't deserialize bundle entry " + bundleEntry.name);
         }
         fs.Dispose();
     }
 }
开发者ID:qq573011406,项目名称:UnityAssetTool,代码行数:27,代码来源:TypeTreeDataBaseLearnCommand.cs

示例7: run

        public void run()
        {
            MGraph pMGraph = new MGraph();
            pMGraph.init(3, 3, 1, 1);

            List<Vertex> vertList;
            FileStream pFile = new FileStream("E:\\aaa.txt", FileMode.Create);
            string strStream = "";

            vertList = test5Stop(pMGraph);
            serializePath(vertList, ref strStream);
            pMGraph.clearAllStopPoint();
            pMGraph.clearPath();

            vertList = test4Stop(pMGraph);
            serializePath(vertList, ref strStream);
            pMGraph.clearAllStopPoint();
            pMGraph.clearPath();

            vertList = test2Stop(pMGraph);
            serializePath(vertList, ref strStream);
            pMGraph.clearAllStopPoint();
            pMGraph.clearPath();

            vertList = test2Stop(pMGraph);
            serializePath(vertList, ref strStream);
            pMGraph.clearAllStopPoint();
            pMGraph.clearPath();

            byte[] inBytes = System.Text.Encoding.UTF8.GetBytes(strStream);
            pFile.Write(inBytes, 0, inBytes.Length);
            pFile.Close();
            pFile.Dispose();
        }
开发者ID:quinsmpang,项目名称:Tools,代码行数:34,代码来源:TestAStar.cs

示例8: FileToByteArray

        public byte[] FileToByteArray(string _FileName)
        {
            byte[] _Buffer = null;

            try
            {
                // Open file for reading
                System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);

                // attach filestream to binary reader
                System.IO.BinaryReader _BinaryReader = new System.IO.BinaryReader(_FileStream);

                // get total byte length of the file
                long _TotalBytes = new System.IO.FileInfo(_FileName).Length;

                // read entire file into buffer
                _Buffer = _BinaryReader.ReadBytes((Int32)_TotalBytes);

                // close file reader
                _FileStream.Close();
                _FileStream.Dispose();
                _BinaryReader.Close();
            }
            catch (Exception _Exception)
            {
                // Error
                Console.WriteLine("File Read Error: ", _Exception.ToString());
            }

            return _Buffer;
        }
开发者ID:kohenkatz,项目名称:piwigo-extensions-svn-mirror,代码行数:31,代码来源:StatusForm.cs

示例9: TIM

 public TIM(string path, byte arg0 = 0, bool paramsOnly = false)
 {
     this.arg0 = arg0 != 0;
     this.path = path;
     fs = new FileStream(path, FileMode.Open, FileAccess.Read);
     br = new BinaryReader(fs);
     texture = new Texture();
     bpp = RecognizeBPP();
     if (bpp == -1 && arg0==0)
     {
         Console.WriteLine("TIM: This is not TIM texture!");
         return;
     }
     if (arg0 == 0 && !paramsOnly)
     {
         ReadParameters(bpp);
         bmp = DrawTexture();
     }
     if (arg0 == 0 && paramsOnly)
     {
         ReadParameters(bpp);
     }
     br.Dispose();
     fs.Dispose();
 }
开发者ID:MaKiPL,项目名称:FF8-Rinoa-s-Toolset,代码行数:25,代码来源:TIM.cs

示例10: NonLockingOpen

		/// <summary>
		/// Provides a memory copy of an original image file
		/// </summary>
		/// <param name="filename"></param>
		/// <returns></returns>
		public static System.Drawing.Image NonLockingOpen(string filename)
		{
			try {
				System.Drawing.Image result;
				
				#region Save file to byte array
				
				long size = (new FileInfo(filename)).Length;
				FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
				byte[] data = new byte[size];
				try {
					fs.Read(data, 0, (int)size);
				} finally {
					fs.Close();
					fs.Dispose();
				}
				
				#endregion
				
				#region Convert bytes to image
				
				MemoryStream ms = new MemoryStream();
				ms.Write(data, 0, (int)size);
				result = new Bitmap(ms);
				ms.Close();
				
				#endregion
				
				return result;
				
			} catch (Exception ex) {
				throw ex;
			}
			
		}
开发者ID:jiashida,项目名称:cameratrapmanager,代码行数:40,代码来源:ConversionUtilities.cs

示例11: Slice

        /* INPUT 1:
        ../../Faded.mp4
        ../../
        5
        INPUT 2:
        ../../text.txt
        ../../
        3

         * * * */
        private static void Slice(string sourceFile, string destinationDirectory, int parts)
        {
            FileStream reader = new FileStream(sourceFile, FileMode.Open);
            FileInfo file = new FileInfo(sourceFile);
            long chunkSize = (long)(file.Length/parts);
            BigInteger counter = -1;
            if (file.Length%2 == 1)
            {
                counter = 0;
            }
            int fileCounter = 1;
            int readBytesVariable = reader.ReadByte();
            List<byte> lsBytes = new List<byte>();
            lsBytes.Add((byte)readBytesVariable);
            while (readBytesVariable != -1)
            {

                if ((counter%chunkSize == 0 && counter != 0) || counter == file.Length)
                {
                    string fileName = destinationDirectory + "Part-" + fileCounter + "." + sourceFile.Split(new char[]{'.'},StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
                    FileStream writer = new FileStream(fileName, FileMode.Create,FileAccess.Write);
                    writer.Write(lsBytes.ToArray(), 0,lsBytes.Count);
                    writer.Flush();
                    writer.Dispose();
                    lsBytes.Clear();
                    fileCounter++;
                }

                readBytesVariable = reader.ReadByte();
                lsBytes.Add((byte)readBytesVariable);
                counter++;
            }
        }
开发者ID:exploitx3,项目名称:C-Sharp-,代码行数:43,代码来源:Slicing+File.cs

示例12: Write

 public void Write(Exception ex)
 {
     try
     {
         string filePath = this._fileName;
         lock (obj)
         {
             using (FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.Delete | FileShare.ReadWrite))
             {
                 using (StreamWriter sw = new StreamWriter(fs))
                 {
                     sw.WriteLine(DateTimeFormat.LongTimeFormat + " : " + ex);
                     //sw.Flush();
                     sw.Close();
                     fs.Close();
                     sw.Dispose();
                     fs.Dispose();
                 }
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
开发者ID:ChegnduJackli,项目名称:Projects,代码行数:26,代码来源:FileDAL.cs

示例13: GetCustomerCredentials

        /// <summary>
        /// To Get the user credentials from Customer Resource file
        /// </summary>
        /// Authour: Pradeep
        /// <param name="custType">Type of the customer</param>
        /// <returns>returns an array with UserName and Password</returns>
        /// Created Date: 22-Dec-2011
        /// Modified Date: 22-Dec-2011
        /// Modification Comments
        public static string[] GetCustomerCredentials(string custType)
        {
            try
            {
                Stream stream = new System.IO.FileStream(ResFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
                var resFileData = new ResXResourceReader(stream);
                IDictionaryEnumerator resFileDataDict = resFileData.GetEnumerator();
                var customerCreds = new string[2];
                while (resFileDataDict.MoveNext())
                {
                    if (custType.ToString(CultureInfo.InvariantCulture) == resFileDataDict.Key.ToString())
                    {
                        string temp = resFileDataDict.Value.ToString();
                        customerCreds = temp.Split(';');
                        break;
                    }
                }

                resFileData.Close();
                stream.Dispose();
                return customerCreds;

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                return null;

            }
        }
开发者ID:hemap,项目名称:PhoenixAutomationRepo,代码行数:40,代码来源:Common.cs

示例14: SetDebug

        /// <summary>
        /// 设置调试
        /// </summary>
        /// <param name="isDebug"></param>
        internal static void SetDebug(bool isDebug)
        {
            string content = String.Empty;
            bool isChange = false;

            using (StreamReader fs = new StreamReader(String.Format("{0}Web.config", AppDomain.CurrentDomain.BaseDirectory)))
            {
                content = fs.ReadToEnd();
                fs.Dispose();
            }

            Regex reg = new Regex("<compilation([^(debug)])+debug=\"([^\"]+)\"", RegexOptions.IgnoreCase);
            if (reg.IsMatch(content))
            {
                Match m = reg.Match(content);
                if ((m.Groups[2].Value == "true" && !isDebug) || (m.Groups[2].Value == "false" && isDebug))
                {
                    content = reg.Replace(content, String.Format("<compilation$1debug=\"{0}\"", isDebug ? "true" : "false"));
                    isChange = true;
                }
            }

            if (isChange)
            {
                using (FileStream fs = new FileStream(String.Format("{0}Web.config", AppDomain.CurrentDomain.BaseDirectory),
                    FileMode.Truncate, FileAccess.Write,FileShare.ReadWrite))
                {
                    byte[] data = Encoding.UTF8.GetBytes(content);
                    fs.Write(data, 0, data.Length);
                    fs.Flush();
                    fs.Dispose();
                }
            }
        }
开发者ID:AntonWong,项目名称:cms,代码行数:38,代码来源:WebConfig.cs

示例15: ConfigIni

 public ConfigIni()
 {
     StreamReader sr = new StreamReader(Basic_HTB_Info.baseFilePath + @"\Config.txt", Encoding.Default);
     string line = null;
     while ((line = sr.ReadLine()) != null)
     {
         string[] s_ar = line.Split('=');
         if (s_ar[0] == "DB_HOST") DB_HOST = s_ar[1];
         if (s_ar[0] == "output_result_html") output_result_html = s_ar[1];
         if (s_ar[0] == "report_to_public") report_to_public = s_ar[1];
         if (s_ar[0] == "temp_dir") temp_dir = s_ar[1];
         if (s_ar[0] == "blanktable_to_public") blanktable_to_public = s_ar[1];
     }
     sr.Close();
     sr.Dispose();
     using (FileStream xmlfs = new FileStream(Basic_HTB_Info.baseFilePath + @"\tempdata.txt",FileMode.Open))
     {
         XmlTextReader xmlr = new XmlTextReader(xmlfs);
         String tempstr = null;
         while (xmlr.Read())
         {
             if (xmlr.NodeType == XmlNodeType.Element)
             {
                 if (xmlr.Name == "tempdata") continue;
                 tempstr = xmlr.Name;
             }
             else if (xmlr.NodeType == XmlNodeType.Text)
             {
                 tempdata.Add(tempstr, xmlr.Value);
             }
         }
         xmlfs.Close();
         xmlfs.Dispose();
     }
 }
开发者ID:eddylin2015,项目名称:sportday,代码行数:35,代码来源:ConfigIni.cs


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