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


C# IO.StreamWriter类代码示例

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


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

示例1: ExtractTextFromPdf

        public static string ExtractTextFromPdf(string path)
        {
            ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy();

            using (PdfReader reader = new PdfReader(path))
            {
                StringBuilder text = new StringBuilder();

                for (int page = 1; page <= reader.NumberOfPages; page++)
                {
                    ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();

                    string currentText = PdfTextExtractor.GetTextFromPage(reader, page, strategy);

                    currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
                    text.Append(currentText);
                }

                System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");
                file.WriteLine(text);

                file.Close();

                return text.ToString();
            }
        }
开发者ID:james-catterall,项目名称:Parsing-to-file,代码行数:26,代码来源:Program.cs

示例2: TryPrint

        public void TryPrint(string zplCommands)
        {
            try
            {
                // Open connection
                System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
                client.Connect(this.m_IPAddress, this.m_Port);

                // Write ZPL String to connection
                System.IO.StreamWriter writer = new System.IO.StreamWriter(client.GetStream());
                writer.Write(zplCommands);
                writer.Flush();

                // Close Connection
                writer.Close();
                client.Close();
            }
            catch (Exception ex)
            {
                this.m_ErrorCount += 1;
                if(this.m_ErrorCount < 10)
                {
                    System.Threading.Thread.Sleep(5000);
                    this.TryPrint(zplCommands);
                }
                else
                {
                    throw ex;
                }
            }
        }
开发者ID:ericramses,项目名称:YPILIS,代码行数:31,代码来源:ZPLPrinter.cs

示例3: Main

        static void Main(string[] args)
        {
            string nombreFichero = "log_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".txt";
            Process[] procesos = null;
            string wanted = "java";

            using (System.IO.StreamWriter fichero = new System.IO.StreamWriter(nombreFichero))
            {
                fichero.WriteLine("==========================================================================================");
                fichero.WriteLine("==========================================================================================");
                fichero.WriteLine("Fecha y hora de inicio: " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                fichero.WriteLine("");
                fichero.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\t\tObteniendo listado de procesos.");

                procesos = Process.GetProcesses();

                fichero.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\t\tListado de procesos obtenido.");
                fichero.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\t\tProceso a buscar: " + wanted);
                foreach (Process proceso in procesos)
                {
                    if (proceso.ProcessName.ToLower() == wanted)
                    {
                        fichero.Write(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\t\tProceso " + wanted + " ("+ proceso.Id +") encontrado...");
                        Process p = Process.GetProcessById(proceso.Id);
                        p.Kill();
                        fichero.Write(" eliminado.\n");
                    }
                }
                fichero.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\t\tBúsqueda finalizada.");
            }
        }
开发者ID:disalinas,项目名称:mata_dragones,代码行数:31,代码来源:Program.cs

示例4: WriteLog

        public static void WriteLog(string UserAgent, string Url, string Message, string StackTrace)
        {
            try
            {
                //Write Log
                var folderPath = string.Format(@"D:\SBSV\{0}", DateTime.Now.ToString("dd_MM_yyyy"));

                if (!System.IO.Directory.Exists(folderPath))
                {
                    System.IO.Directory.CreateDirectory(folderPath);
                }

                var filePath = string.Format(@"{0}\{1}.txt", folderPath, DateTime.Now.ToString("dd_MM_yyyy"));
                System.IO.TextWriter tw = new System.IO.StreamWriter(filePath, true);
                tw.WriteLine("UserAgent {0}", UserAgent);
                tw.WriteLine("Date {0}", DateTime.Now);
                tw.WriteLine("Url {0} ", Url);
                tw.WriteLine("Message {0} ", Message);
                tw.WriteLine("Log Contents: ");
                tw.WriteLine(StackTrace);
                tw.WriteLine("--------------------------------------------------------------");
                tw.Close();
                //Write Log
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
            }
        }
开发者ID:kiran3490,项目名称:SBSV.Web,代码行数:29,代码来源:InternalLog.cs

示例5: Main

        static void Main(string[] args)
        {
            string[] funcListUrls = {
                                        //"http://www.xqueryfunctions.com/xq/c0008.html",
                                        //"http://www.xqueryfunctions.com/xq/c0011.html",
                                        //"http://www.xqueryfunctions.com/xq/c0002.html",
                                        //"http://www.xqueryfunctions.com/xq/c0013.html",
                                        //"http://www.xqueryfunctions.com/xq/c0015.html",
                                        "http://www.xqueryfunctions.com/xq/c0026.html",
                                        "http://www.xqueryfunctions.com/xq/c0033.html",
                                        "http://www.xqueryfunctions.com/xq/c0021.html",
                                        "http://www.xqueryfunctions.com/xq/c0023.html",
                                        "http://www.xqueryfunctions.com/xq/c0072.html"
                                    };

            foreach (string funcListUrl in funcListUrls)
            {
                FuncList[] funcLists = ParseFuncList(funcListUrl);
                foreach (FuncList funcList in funcLists)
                {
                    System.IO.StreamWriter testFile = new System.IO.StreamWriter(TESTCASE_FILE, true);
                    testFile.WriteLine("\n<!-- " + funcList.funcName + " - " + funcList.subcat + ": " + funcList.funclist.Length + " cases -->");
                    testFile.Close();
                    testFile = null;
                    foreach (string name in funcList.funclist)
                    {
                        string url = "http://www.xqueryfunctions.com/xq/functx_" + name + ".html";
                        Console.WriteLine("Parsing " + url + " ...");
                        ParseURL(funcList.funcName, funcList.subcat, url);
                    }
                }
            }
        }
开发者ID:yezilaoda,项目名称:mytoolkits,代码行数:33,代码来源:Program.cs

示例6: Main

        public static void Main(string[] args)
        {
            Defrag.IFileSystem fileSystem = new Defrag.Win32FileSystem("C:");
            Defrag.Optimizer optimizer = new Defrag.Optimizer(fileSystem);

            Defrag.Win32ChangeWatcher watcher = new Defrag.Win32ChangeWatcher("C:\\");
            System.IO.TextWriter log = new System.IO.StreamWriter(System.Console.OpenStandardOutput());

            while (true)
            {
                String path = watcher.NextFile();
                if (path != null)
                {
                    try
                    {
                        optimizer.DefragFile(path, log);
                    }
                    catch (Win32Exception ex)
                    {
                        log.WriteLine(ex.Message);
                        log.WriteLine("* * Failed! * *");
                    }
                    finally
                    {
                        log.WriteLine();
                        log.Flush();
                    }
                }
                else
                {
                    Thread.Sleep(500);
                }
            }
        }
开发者ID:pauldoo,项目名称:scratch,代码行数:34,代码来源:Program.cs

示例7: Error

        public static void Error()
        {
            IntPtr ptr;

            Assert.Throws<Exception>(() => DynamicLibrary.Open("NOT_EXISTING"));

            string failure = "FAILURE";
            var fs = new System.IO.StreamWriter(System.IO.File.OpenWrite(failure));
            fs.Write("foobar");
            fs.Close();

            Assert.IsTrue(System.IO.File.Exists(failure));
            Assert.Throws<Exception>(() => DynamicLibrary.Open(failure));

            System.IO.File.Delete(failure);

            var dl = DynamicLibrary.Open(DynamicLibrary.Decorate("uv"));

            Assert.IsTrue(dl.TryGetSymbol("uv_default_loop", out ptr));
            Assert.AreNotEqual(ptr, IntPtr.Zero);

            Assert.IsFalse(dl.TryGetSymbol("NOT_EXISTING", out ptr));
            Assert.AreEqual(ptr, IntPtr.Zero);

            Assert.Throws<Exception>(() => dl.GetSymbol("NOT_EXISTING"));

            Assert.IsFalse(dl.Closed);
            dl.Close();
            Assert.IsTrue(dl.Closed);
        }
开发者ID:oskarwkarlsson,项目名称:LibuvSharp,代码行数:30,代码来源:DynamicLibraryFixture.cs

示例8: OnStart

        protected override void OnStart(string[] args)
        {
            using (System.IO.StreamWriter sw = new System.IO.StreamWriter("E:\\log.txt", true))
            {
                sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "start.");
            }

            ISchedulerFactory schedFact = new StdSchedulerFactory();
            // get a scheduler
            IScheduler sched = schedFact.GetScheduler();
            sched.Start();

            // define the job and tie it to our HelloJob class
            IJobDetail job = JobBuilder.Create<HelloWorld>()
                .WithIdentity("myJob", "group1")
                .Build();

            //ITrigger trigger = TriggerBuilder.Create()
            //  .WithIdentity("myTrigger", "group1")
            //  .StartNow()
            //  .WithSimpleSchedule(x => x
            //      .WithIntervalInHours(1)
            //      .RepeatForever())
            //  .Build();
            ITrigger trigger = TriggerBuilder.Create()
            .WithIdentity("myTrigger", "group1")
            .WithCronSchedule("0/5 * * * * ?")
            .ForJob("myJob", "group1")
            .Build();
            sched.ScheduleJob(job, trigger);
        }
开发者ID:TGHGH,项目名称:MesDemo,代码行数:31,代码来源:ServiceHr.cs

示例9: btnSave_Click

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            RadioButton rbFullScreen = UIHelpers.FindChild<RadioButton>(this, "rbFullScreen");

            if (rbFullScreen.IsChecked.Value)
            {
                Settings.GetInstance().Mode = Settings.ScreenMode.Fullscreen;
                PageNavigator.MainWindow.WindowStyle = WindowStyle.None;
                PageNavigator.MainWindow.WindowState = WindowState.Maximized;
                PageNavigator.MainWindow.Focus();
            }
            else
            {
                Settings.GetInstance().Mode = Settings.ScreenMode.Windowed;
            }

            ComboBox cbLanguage = UIHelpers.FindChild<ComboBox>(this, "cbLanguage");
            AppSettings.GetInstance().setLanguage((Language)cbLanguage.SelectedItem);

            System.IO.StreamWriter file = new System.IO.StreamWriter(AppSettings.getCommonApplicationDataPath() + "\\game.settings");
            file.WriteLine(AppSettings.GetInstance().getLanguage().Name);
            file.WriteLine(Settings.GetInstance().Mode);
            file.Close();

            //PageNavigator.NavigateTo(new PageStartMenu());
        }
开发者ID:pedromorgan,项目名称:theairlineproject-cs,代码行数:26,代码来源:PageSettings.xaml.cs

示例10: save

 public void save()
 {
     System.IO.StreamWriter m_stwSave = new System.IO.StreamWriter(".\\CCDate.dat", false);
     m_stwSave.WriteLine(strCCKey);
     m_stwSave.WriteLine(strSaveKey);
     m_stwSave.Close();
 }
开发者ID:ViGor-Thinktank,项目名称:GCML,代码行数:7,代码来源:clsCampaignInfo.cs

示例11: InitBlock

		private void  InitBlock()
		{
			System.IO.StreamWriter temp_writer;
			temp_writer = new System.IO.StreamWriter(System.Console.OpenStandardOutput(), System.Console.Out.Encoding);
			temp_writer.AutoFlush = true;
			debugStream = temp_writer;
		}
开发者ID:Inzaghi2012,项目名称:teamlab.v7.5,代码行数:7,代码来源:HTMLParserTokenManager.cs

示例12: Send

        public void Send(object sender, EventArgs args)
        {
            try
            {
                var publishArgs = args as Sitecore.Events.SitecoreEventArgs;

                var publisher = publishArgs.Parameters[0] as Sitecore.Publishing.Publisher;

                var publisherOptions = publisher.Options;

                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("localhost");

                mail.From = new MailAddress("[email protected]");
                mail.To.Add("[email protected]");
                mail.Subject = "Someone published the item " + publisherOptions.RootItem.Paths.FullPath;
                mail.Body = publisherOptions.RootItem.Fields["body"].Value;
                SmtpServer.Send(mail);

                string lines = publisherOptions.RootItem.Fields["body"].Value;

                // Write the string to a file.
                System.IO.StreamWriter file = new System.IO.StreamWriter("D:\\Git\\Eduserv-Github-Example\\Source\\Website\\BritishLibrary.Website\\test.xml");
                file.WriteLine(lines);

                file.Close();

            }
            catch (Exception ex)
            {
                Console.WriteLine("Seems some problem!");
            }
        }
开发者ID:Adamsimsy,项目名称:Eduserv-Github-Example,代码行数:33,代码来源:SendEmailNotification.cs

示例13: LoadTestCredential

        private void LoadTestCredential()
        {
            string path = @"C:\Temp\AmazonAwsS3Test.xml";
            Models.AwsCredential credential;
            var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Models.AwsCredential));

            if (!System.IO.File.Exists(path))
            {
                //Cria um arquivo xml novo, se já não existir um
                credential = new Models.AwsCredential();
                credential.User = string.Empty;
                credential.AccessKeyId = string.Empty;
                credential.SecretAccessKey = string.Empty;
                credential.Region = string.Empty;

                using (var streamWriter = new System.IO.StreamWriter(path))
                {
                    xmlSerializer.Serialize(streamWriter, credential);
                }
            }

            //Carrega o xml
            using (var streamReader = new System.IO.StreamReader(path))
            {
                credential = (Models.AwsCredential)xmlSerializer.Deserialize(streamReader);
            }

            txtAccessKeyId.Text = credential.AccessKeyId;
            txtSecretAccessKey.Text = credential.SecretAccessKey;
            txtRegion.Text = credential.Region;
        }
开发者ID:educoutinho,项目名称:AmazonAwsS3Test,代码行数:31,代码来源:MainForm.cs

示例14: DumpGossipMenu

        public static string DumpGossipMenu()
        {
            var file = "GossipMenuLog_" + DateTime.Now.ToString("MM-dd-yyyy-hh-mm-ss") + ".sql";
            var gossip_menus = GossipMenuList.OrderByDescending(t => t.Key);
            using (var sw = new System.IO.StreamWriter(file))
            {
                foreach (var gossip_menu in gossip_menus)
                {
                    sw.WriteLine(gossip_menu.Value.GetDeleteCommand());
                    sw.WriteLine(gossip_menu.Value.GetInsertCommand());
                    if (gossip_menu.Value.creature_template != null)
                    {
                        sw.WriteLine();
                        sw.WriteLine(gossip_menu.Value.creature_template.GetUpdateCommand());
                    }
                    
                    if (gossip_menu.Value.gossip_menu_options != null && gossip_menu.Value.gossip_menu_options.Any())
                    {
                        sw.WriteLine();

                        sw.WriteLine(gossip_menu.Value.gossip_menu_options.First().Value.GetDeleteCommand());

                        foreach (var gossip_menu_option in gossip_menu.Value.gossip_menu_options)
                        {
                            sw.WriteLine(gossip_menu_option.Value.GetInsertCommand());
                        }
                    }
                    sw.WriteLine();
                }
            }

            return file;
        }
开发者ID:RaptorFactor,项目名称:devmaximus,代码行数:33,代码来源:GossipHandler.cs

示例15: WriteException

 public static void WriteException(String pMethod, Exception pException)
 {
     String date = DateTime.Now.ToString("dd/MM/yyyy hh:MM:ss");
     String archieve = "C:\\TEMP\\MIToolDatabaseLog" + DateTime.Now.ToString("dd/MM/yyyy") + ".txt";            
     try
     {
         System.IO.StreamWriter file = new System.IO.StreamWriter(archieve, true);
         file.WriteLine("------------------------------------------");
         file.WriteLine("Method :" + pMethod);
         file.WriteLine("Date :" + date);
         file.WriteLine("Detail");
         file.WriteLine("\n");
         file.WriteLine("Message " + pException.Message);
         file.WriteLine("\n");
         file.WriteLine("StackTrace " + pException.StackTrace);
         file.WriteLine("\n");
         file.WriteLine("Source " + pException.Source);
         file.WriteLine("\n");
         file.WriteLine("ToString() " + pException.ToString());
         file.WriteLine("------------------------------------------");
         file.WriteLine("\n");
         file.Close();
     }
     catch { }
 }
开发者ID:maickher,项目名称:Calidad,代码行数:25,代码来源:Log.cs


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