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

C# IO.StreamWriter类代码示例

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

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



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


示例16: btnSubmit_Click

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //string xml;
               Contact contact = new Contact();

            contact.companyName = txtCompany.Text;
            contact.firstName = txtFName.Text;
            contact.middleName = txtMName.Text;
            contact.lastName = txtLName.Text;
            contact.liscence = txtLicense.Text;
            contact.phone = txtPhone.Text;
            contact.cell = txtCell.Text;
            contact.email = txtEmail.Text;
            contact.buildingLiscence = txtBuildingLicense.Text;
            contact.streetNumber = txtStreetNumber.Text;
            contact.streetName = txtStreetName.Text;
            contact.type = txtType.Text;
            contact.streetName2 = txtStreetName2.Text;
            contact.city = txtCity.Text;
            contact.state = txtState.Text;
            contact.zip = txtZip.Text;
            System.IO.StreamWriter file = new System.IO.StreamWriter(@"Contact.xml");
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(contact.GetType());
            x.Serialize(file, contact);
            file.Close();
        }
开发者ID:sunelaitisd088,项目名称:AberdeenPermitting,代码行数:26,代码来源:ContactInfo.cs


示例17: ExportFilteredDataTableToCsv

 public static void ExportFilteredDataTableToCsv(DataTable targetDataTable, string targetFilePath, string filterString)
 {
     using (System.IO.StreamWriter outFile = new System.IO.StreamWriter(targetFilePath, false, Encoding.UTF8))
     {
         for (int i = 0; i < targetDataTable.Columns.Count; i++)
         {
             outFile.Write("\"");
             outFile.Write(targetDataTable.Columns[i].ColumnName.Replace("\"", "\"\""));
             outFile.Write("\"");
             outFile.Write(i == targetDataTable.Columns.Count - 1 ? Environment.NewLine : ",");
         }
         foreach (DataRow row in targetDataTable.Select(filterString))
         {
             for (int i = 0; i < targetDataTable.Columns.Count; i++)
             {
                 outFile.Write("\"");
                 if (targetDataTable.Columns[i].DataType.Equals(typeof(DateTime)))
                     outFile.Write(FormatDateFullTimeStamp((DateTime)row[i]));
                 else
                     outFile.Write(row[i].ToString().Replace("\"", "\"\""));
                 outFile.Write("\"");
                 outFile.Write(i == targetDataTable.Columns.Count - 1 ? Environment.NewLine : ",");
             }
         }
     }
 }
开发者ID:TaoK,项目名称:NanoTimeTracker,代码行数:26,代码来源:Utils.cs


示例18: save

        /// <summary>
        /// Saves the colourz
        /// </summary>
        public void save()
        {
            if (!System.IO.Directory.Exists(Constants.CACHE_PATH))
            {
                System.IO.Directory.CreateDirectory(Constants.CACHE_PATH);
            }

            if (!System.IO.Directory.Exists(Constants.CACHE_PATH))
            {
                Console.WriteLine("Created directory");
                System.IO.Directory.CreateDirectory(Constants.CACHE_PATH);
            }

            System.IO.File.WriteAllBytes(Constants.CACHE_PATH + "Saved Colours.txt", new byte[0]);
            System.IO.StreamWriter file = new System.IO.StreamWriter(Constants.CACHE_PATH + "Saved Colours.txt", true);
            
            string saveText = "";
            for(int i = 0; i < stack.Children.Count; i++)
            {
                SavedColour s = (SavedColour)stack.Children[i];

                if(i != stack.Children.Count)
                    saveText += s.hex + ";";
            }
            file.WriteLine(saveText);
            file.Flush();
            file.Close();
        }
开发者ID:wolfbytestudio,项目名称:Colourz,代码行数:31,代码来源:ColourzSaver.cs


示例19: Main

        static void Main()
        {
            Process self = Process.GetCurrentProcess();
            Process[] processes = Process.GetProcessesByName(self.ProcessName);
            int selfid = self.Id;
            foreach (Process proc in processes) {
                if (proc.Id != selfid) {
                    NativeMethods.ShowWindow(proc.MainWindowHandle, NativeMethods.SW_NORMAL);
                    NativeMethods.SetForegroundWindow(proc.MainWindowHandle);
                    return;
                }
            }

            Process[] scueduler = Process.GetProcessesByName("cubepower-scheduler");
            foreach (Process proc in scueduler) proc.Kill();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            try {
                Application.Run(new MainForm());
            }
            catch (Exception err) {
                System.Reflection.Assembly exec = System.Reflection.Assembly.GetEntryAssembly();
                string dir = System.IO.Path.GetDirectoryName(exec.Location);
                string path = dir + @"\cubepower.log";
                using (System.IO.StreamWriter output = new System.IO.StreamWriter(path)) {
                    output.WriteLine(err.Message);

                    IPowerScheme scheme;
                    if (Environment.OSVersion.Version.Major > 5) scheme = new PowerSchemeVista();
                    else scheme = new PowerSchemeXP();
                    scheme.Dump(output);
                }
            }
        }
开发者ID:cube-soft,项目名称:CubePowerSaver,代码行数:35,代码来源:Program.cs


示例20: OnStop

 protected override void OnStop()
 {
     using (System.IO.StreamWriter sw = new System.IO.StreamWriter("E:\\log.txt", true))
     {
         sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "Stop.");
     }
 }
开发者ID:TGHGH,项目名称:MesDemo,代码行数:7,代码来源:ServiceHr.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# IO.StringReader类代码示例发布时间:2022-05-24
下一篇:
C# IO.StreamReader类代码示例发布时间: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