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


C# StreamWriter.Close方法代码示例

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


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

示例1: WriteToLog

 /// <summary>
 /// Запись в ЛОГ-файл
 /// </summary>
 /// <param name="str"></param>
 public void WriteToLog(string str, bool doWrite = true)
 {
     if (doWrite)
     {
         StreamWriter sw = null;
         FileStream fs = null;
         try
         {
             string curDir = AppDomain.CurrentDomain.BaseDirectory;
             fs = new FileStream(curDir + "teplouchetlog.pi", FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
             sw = new StreamWriter(fs, Encoding.Default);
             if (m_vport == null) sw.WriteLine(DateTime.Now.ToString() + ": Unknown port: adress: " + m_address + ": " + str);
             else sw.WriteLine(DateTime.Now.ToString() + ": " + m_vport.GetName() + ": adress: " + m_address + ": " + str);
             sw.Close();
             fs.Close();
         }
         catch
         {
         }
         finally
         {
             if (sw != null)
             {
                 sw.Close();
                 sw = null;
             }
             if (fs != null)
             {
                 fs.Close();
                 fs = null;
             }
         }
     }
 }
开发者ID:Prizmer,项目名称:tu_teplouchet,代码行数:38,代码来源:CMeter.cs

示例2: Write

        protected override async void Write(Core.LogEventInfo logEvent)
        {

            var request = (HttpWebRequest) WebRequest.Create(ServerUrl);
            request.ContentType = "application/json; charset=utf-8";
            request.Method = "POST";
            var requestWriter = new StreamWriter(request.GetRequestStream());
            
            requestWriter.Write("{ "
                                + "\"version\": " + "\"" + "1.0" + "\",\n"
                                + "\"host\": " + "\"" + AndroidId + "\",\n"
                                + "\"short_message\": " + "\"" + logEvent.FormattedMessage + "\",\n"
                                + "\"full_message\": " + "\"" + logEvent.FormattedMessage + "\",\n"
                                + "\"timestamp\": " + "\"" + DateTime.Now.ToString(CultureInfo.InvariantCulture) +
                                "\",\n"
                                + "\"level\": " + "\"" +
                                logEvent.Level.Ordinal.ToString(CultureInfo.InvariantCulture) + "\",\n"
                                + "\"facility\": " + "\"" + "NLog Android Test" + "\",\n"
                                + "\"file\": " + "\"" + Environment.CurrentDirectory + "AndroidApp" + "\",\n"
                                + "\"line\": " + "\"" + "123" + "\",\n"
                                + "\"Userdefinedfields\": " + "{}" + "\n"
                                + "}");

            requestWriter.Close();

            LastResponseMessage = (HttpWebResponse) request.GetResponse();
        }
开发者ID:unhappy224,项目名称:NLog.IqMetrix,代码行数:27,代码来源:LumberMillTarget.cs

示例3: ConvertFormat

        public static void ConvertFormat(string strInputFile, string strOutputFile)
        {
            StreamReader sr = new StreamReader(strInputFile);
            StreamWriter sw = new StreamWriter(strOutputFile);
            string strLine = null;

            while ((strLine = sr.ReadLine()) != null)
            {
                strLine = strLine.Trim();

                string[] items = strLine.Split();
                foreach (string item in items)
                {
                    int pos = item.LastIndexOf('[');
                    string strTerm = item.Substring(0, pos);
                    string strTag = item.Substring(pos + 1, item.Length - pos - 2);

                    sw.WriteLine("{0}\t{1}", strTerm, strTag);
                }
                sw.WriteLine();
            }

            sr.Close();
            sw.Close();
        }
开发者ID:zxz,项目名称:RNNSharp,代码行数:25,代码来源:Program.cs

示例4: Extract

        public static void Extract(Category category)
        {
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data", "Extract");
            if(!Directory.Exists(path))
                Directory.CreateDirectory(path);

            pset.Clear();
            pdic.Clear();
            string downPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data", "Down", category.Name);
            string fileName = string.Format(@"{0}\{1}.txt", path, category.Name);

            StreamWriter sw = new StreamWriter(fileName, false, Encoding.UTF8);
            for (int i = category.DownPageCount; i >= 1; i--)
            {
                string htmlFileName = string.Format(@"{0}\{1}.html", downPath, i);
                if (!File.Exists(htmlFileName))
                    Logger.Instance.Write(string.Format("{0}-{1}.html-not exist", category.Name, i));
                StreamReader sr = new StreamReader(htmlFileName, Encoding.UTF8);
                string text = sr.ReadToEnd();
                sr.Close();

                var action = CreateAction(category.Type);
                if (action == null) continue;

                Extract(text, sw, category.Name,category.DbName, action);
            }
            sw.Close();

            Console.WriteLine("{0}:Extract Data Finished!", category.Name);
        }
开发者ID:tavenli,项目名称:gaopincai,代码行数:30,代码来源:ExtractData.cs

示例5: WriteLog

        public static void WriteLog(string message)
        {
            var fileLog = Config.Global.Settings.LOG_PATH + "log_" + System.DateTime.Now.ToString("MM_dd_yyyy") + ".txt";
            message = "\r\nTime: " + System.DateTime.Now.ToString("MM/dd/yyyy h:mm tt") + "\r\n" + message + "\r\n----------------------------------------------------";
            FileStream fs = new FileStream(fileLog, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fs);
            try
            {

                sw.Close();
                fs.Close();

                // Ghi file
                fs = new FileStream(fileLog, FileMode.Append, FileAccess.Write);
                sw = new StreamWriter(fs);
                sw.Write(message);
                sw.Close();
                fs.Close();

            }
            catch
            {
                sw.Close();
                fs.Close();
            }
            finally
            {
                sw.Close();
                fs.Close();
            }
        }
开发者ID:Letractively,项目名称:vtcsoft,代码行数:31,代码来源:Log.cs

示例6: OnStart

        /* The Startup */
        protected override void OnStart(string[] args)
        {
            /* Open a streamwriter */
            StreamWriter streamWriter =
                new StreamWriter("Startup.txt", true);
            try
            {
                this.Host = new ServiceHost(typeof(EIAService), new Uri[0]);
                this.Host.Open();
            }
            catch (Exception ex)
            {
                streamWriter.WriteLine(ex.ToString());
                streamWriter.Flush();
                streamWriter.Close();
                return;
            }

            /* Spit it out */
            streamWriter.WriteLine("Service up and running at:");
            foreach (ServiceEndpoint serviceEndpoint in (Collection<ServiceEndpoint>)this.Host.Description.Endpoints)
                streamWriter.WriteLine((object)serviceEndpoint.Address);
            streamWriter.Flush();
            streamWriter.Close();
        }
开发者ID:PrivateOrganizationC,项目名称:Primary,代码行数:26,代码来源:ApiService.cs

示例7: SerializeToText

        public static string SerializeToText(System.Type ObjectType, Object Object)
        {
            string RetVal;
            StreamWriter Writer;
            StreamReader Reader;
            MemoryStream Stream;

            RetVal = string.Empty;
            Stream = new MemoryStream();
            Reader = new StreamReader(Stream);
            Writer = new StreamWriter(Stream);

            try
            {
                if (Object != null && ObjectType != null)
                {
                    Serialize(Writer, ObjectType, Object);
                    Stream.Position = 0;
                    RetVal = Reader.ReadToEnd();

                    Writer.Flush();
                    Writer.Close();
                    Reader.Close();
                }
            }
            catch (Exception ex)
            {
                Writer.Flush();
                Writer.Close();
                Reader.Close();
                throw ex;
            }
            return RetVal;
        }
开发者ID:SDRC-India,项目名称:sdrcdevinfo,代码行数:34,代码来源:Serializer.cs

示例8: WriteFiles

                  public void WriteFiles(string content)
                  {

                        try
                        {
                              FileStream fi = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\cache.txt", FileMode.Append);
                              StreamWriter sw = new StreamWriter(fi, Encoding.UTF8);

                              sw.WriteLine(content);
                              sw.WriteLine("-------------------------------------------------------");

                              if (fi.Length >= (1024 * 1024 * 5))
                              {
                                    sw.Close();
                                    fi.Close();
                                    if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\cache.txt"))
                                    {
                                          File.Delete(AppDomain.CurrentDomain.BaseDirectory + "\\cache.txt");
                                    }
                                    return;
                              }
                              sw.Close();
                              fi.Close();
                        }
                        catch (Exception ex)
                        {

                        }
                  }
开发者ID:SiteView,项目名称:ECC8.13,代码行数:29,代码来源:ErrorLog.cs

示例9: Export

 /// <summary>
 /// Exports an answer matrix to a file.
 /// </summary>
 /// <param name="answerMatrix">Answer matrix</param>
 /// <param name="filename">Output file path</param>
 public static void Export(TLSimilarityMatrix answerMatrix, string filename)
 {
     TextWriter tw = null;
     try
     {
         tw = new StreamWriter(filename);
         foreach (string sourceID in answerMatrix.SourceArtifactsIds)
         {
             tw.Write(sourceID);
             foreach (string targetID in answerMatrix.GetSetOfTargetArtifactIdsAboveThresholdForSourceArtifact(sourceID))
             {
                 tw.Write(" " + targetID);
             }
             tw.WriteLine();
         }
         tw.Flush();
         tw.Close();
     }
     catch (Exception e)
     {
         if (tw != null)
         {
             tw.Close();
         }
         throw new DevelopmentKitException("There was an exception writing to file (" + filename + ")", e);
     }
 }
开发者ID:CoEST,项目名称:TraceLab-CDK,代码行数:32,代码来源:Oracle.cs

示例10: IsTemplateEnabledFor

 public static bool IsTemplateEnabledFor(object target, string templateName, DTE service = null)
 {
     try
     {
         var selectedItem = target as ProjectItem;
         if (selectedItem == null)
         {
             return false;
         }
         string selectedFolderPath = DteHelper.GetFilePathRelative(selectedItem);
         var templatePath = TemplateConfiguration.GetConfiguration(service).ExtRootFolderName + "\\" + templateName;
         var wr = new StreamWriter(@"C:\test.text", true);
         if (selectedFolderPath.ToLower().Contains(templatePath.ToLower()))
         {
             wr.WriteLine("SelectedFolderPath:{0}, TemplatePath:{1}, Valid", selectedFolderPath, templatePath);
             wr.Close();
             return true;
         }
         wr.WriteLine("SelectedFolderPath:{0}, TemplatePath:{1}, Invalid", selectedFolderPath, templatePath);
         wr.Close();
         return false;
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format(ErrorMessages.GeneralError, ex.Message), MessageType.Error,
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
         return false;
     }
 }
开发者ID:andyshao,项目名称:extjs-mvc-templates-for-visual-studio,代码行数:30,代码来源:GeneralUtility.cs

示例11: addLog

        public void addLog(string method, string kind, string msg, LogType logType)
        {
            string localPath = "";
            string logPath = AppDomain.CurrentDomain.BaseDirectory + "log/" + logType.ToString() + "/";
            localPath = string.Format(logPath + "{0:yyyyMMdd}.log", DateTime.Now);
            lock (localPath)
            {
                StreamWriter writer = null;
                try
                {
                    System.IO.FileInfo info = new FileInfo(localPath);
                    if (!info.Directory.Exists)
                        info.Directory.Create();

                    writer = new StreamWriter(localPath, true, System.Text.Encoding.UTF8);
                    writer.WriteLine(string.Format("{0}[{1:HH:mm:ss}] 方法{2} 用户:{3}[end]", kind, DateTime.Now, method, msg));
                }
                catch
                {
                    if (writer != null)
                        writer.Close();
                }
                finally
                {
                    if (writer != null)
                        writer.Close();
                }
            }
        }
开发者ID:drawde,项目名称:DidYouSeeMyLittleBear,代码行数:29,代码来源:Log.cs

示例12: CommitQuizAnswers

        private static void CommitQuizAnswers(String quizAnswers, String personName, String setupID)
        {
            XmlSerializer writer;
            StreamWriter quizAnswersFile = null;
            DataSet quizData = null;
            try
            {
                if (String.IsNullOrEmpty(quizAnswers))
                    return;

                quizData = RetrieveQuizAnswersData();

                //Create the dataset of answers
                quizData.Tables[0].Rows.Add(setupID, personName, quizAnswers, DateTime.Now);

                writer = new XmlSerializer(typeof(DataSet));
                quizAnswersFile = new StreamWriter(QuizAnswersFilePath);
                writer.Serialize(quizAnswersFile, quizData);
                quizAnswersFile.Close();
                quizAnswersFile.Dispose();
            }
            catch (Exception ex)
            {
                RippleCommonUtilities.LoggingHelper.LogTrace(1, "Went wrong in CommitQuizAnswers at Screen side {0}", ex.Message);
                writer = null;
                if (quizAnswersFile != null)
                {
                    quizAnswersFile.Close();
                    quizAnswersFile.Dispose();
                }
            }
        }
开发者ID:guozanhua,项目名称:kinect-ripple,代码行数:32,代码来源:QuizAnswersWriter.cs

示例13: Game_OnChat

 static void Game_OnChat(GameChatEventArgs args)
 {
     if (!main.Item("enabled").GetValue<bool>())
         return;
     try{
         var stream = new StreamWriter(_path, true, Encoding.UTF8);
         if (args.Sender.IsAlly)
         {
             stream.WriteLine("[" + Utils.FormatTime(Game.ClockTime) + "]" + " sender: " + args.Sender.Name + " says: " + args.Message);
             stream.Close();
         }
         else
         {
             stream.WriteLine("[" + Utils.FormatTime(Game.ClockTime) + "]" + "[enemy] sender: " + args.Sender.Name + " says: " + args.Message);
             stream.Close();
         }
         if (main.Item("notify").GetValue<bool>())
             Notifications.AddNotification(new Notification("Chat loged",500).SetBoxColor(Color.Black).SetTextColor(Color.Green));
         if (main.Item("delay").GetValue<int>()!=0)
             System.Threading.Thread.Sleep(main.Item("delay").GetValue<int>());
     }
     catch (Exception e)
     {
         //Notifications.AddNotification("ChatLog error: " + e.Message,1000);
     }
 }
开发者ID:UNREADPROJECTS,项目名称:LeagueSharp,代码行数:26,代码来源:Program.cs

示例14: createCsv

        static float vel_Prec = 0; // Contiene il valore della velocità all'ultimo istante della finestra precedente.

        #endregion Fields

        #region Methods

        // Metodo per la scrittura e creazione del .csv che contiene i dati.
        public static void createCsv(float[,,] sampwin, string path)
        {
            StreamWriter file = new StreamWriter(@path, true);
            string stream = "";

            for (int s = 0; s < sampwin.GetLength(0); s++)
            {
                stream = stream + "SENSORE " + (s + 1) + ":" + "\n" + "\n";
                for (int i = 0; i < sampwin.GetLength(1); i++)
                {
                    for (int j = 0; j < sampwin.GetLength(2); j++)
                    {
                        stream = stream + sampwin[s, i, j].ToString() + ";";
                    }
                    stream = stream + "\n";
                }
                stream = stream + "\n";

                try
                {
                    file.Write(stream);
                    stream = "";
                }
                catch (Exception e)
                {
                    file.Close(); stream = "";
                }
            }

            file.Close();
        }
开发者ID:ryick-V,项目名称:Chuukaku,代码行数:38,代码来源:Program.cs

示例15: SaveInfo3

 public void SaveInfo3(string data, string filename)
 {
     StreamWriter sw = null;
     try
     {
         FileStream fs = File.Open(filename, FileMode.Open);
         sw = new StreamWriter(fs);
         sw.Write(data);
         sw.Close();
     }
     catch (FileNotFoundException fnfex)
     {
         Console.WriteLine("File does not exist: {0}\n",
             fnfex.Message);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Unexpected exception:{0}\n",
             ex.Message);
     }
     finally
     {
         if (sw != null)
         {
             sw.Close();
         }
     }
 }
开发者ID:jhpaterson,项目名称:OOSDLectures,代码行数:28,代码来源:InfoSaver.cs


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