本文整理汇总了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();
}
}
示例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;
}
}
}
示例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.");
}
}
示例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
{
}
}
示例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);
}
}
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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());
}
示例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();
}
示例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;
}
示例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!");
}
}
示例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;
}
示例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;
}
示例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 { }
}