本文整理汇总了C#中System.IO.StreamWriter.WriteLine方法的典型用法代码示例。如果您正苦于以下问题:C# StreamWriter.WriteLine方法的具体用法?C# StreamWriter.WriteLine怎么用?C# StreamWriter.WriteLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamWriter
的用法示例。
在下文中一共展示了StreamWriter.WriteLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
using (StreamWriter str = new StreamWriter(args[0]))
{
int a = Convert.ToInt32(args[1]);
int b = Convert.ToInt32(args[2]);
str.WriteLine("Parameters:");
str.WriteLine(a);
str.WriteLine(b);
int min;
if (a > b)
min = b;
else
min = a;
int i = min;
int c = 0;
while (i>0&&c==0)
{
if ((a % i == 0) && (b % i == 0))
c = i;
i--;
}
//c = 0;
str.WriteLine("Answers:");
str.WriteLine(Convert.ToString(c));
//str.WriteLine(a);
}
}
示例2: AllFieldsEmptyTest
public void AllFieldsEmptyTest()
{
using( var stream = new MemoryStream() )
using( var reader = new StreamReader( stream ) )
using( var writer = new StreamWriter( stream ) )
using( var parser = new CsvParser( reader ) )
{
writer.WriteLine( ";;;;" );
writer.WriteLine( ";;;;" );
writer.Flush();
stream.Position = 0;
parser.Configuration.Delimiter = ";;";
parser.Configuration.HasHeaderRecord = false;
var row = parser.Read();
Assert.IsNotNull( row );
Assert.AreEqual( 3, row.Length );
Assert.AreEqual( "", row[0] );
Assert.AreEqual( "", row[1] );
Assert.AreEqual( "", row[2] );
row = parser.Read();
Assert.IsNotNull( row );
Assert.AreEqual( 3, row.Length );
Assert.AreEqual( "", row[0] );
Assert.AreEqual( "", row[1] );
Assert.AreEqual( "", row[2] );
row = parser.Read();
Assert.IsNull( row );
}
}
示例3: ExportToExcel
private void ExportToExcel()
{
DgStats.SelectAllCells();
DgStats.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
ApplicationCommands.Copy.Execute(null, DgStats);
var stats = (string) Clipboard.GetData(DataFormats.CommaSeparatedValue);
//String result = (string)Clipboard.GetData(DataFormats..Text);
DgStats.UnselectAllCells();
DgUnmatched.SelectAllCells();
DgUnmatched.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
ApplicationCommands.Copy.Execute(null, DgUnmatched);
var unmatched = (string) Clipboard.GetData(DataFormats.CommaSeparatedValue);
DgUnmatched.UnselectAllCells();
var saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = string.Format("{0}.Reconcile.csv", Path.GetFileName(_vm.BankFile.FilePath));
if (saveFileDialog.ShowDialog() == true)
{
var file = new StreamWriter(saveFileDialog.FileName);
file.WriteLine(stats);
file.WriteLine("");
file.WriteLine(unmatched);
file.Close();
}
}
示例4: Trace
public void Trace(NetState state)
{
try
{
string path = Path.Combine(Paths.LogsDirectory, "packets.log");
using (StreamWriter sw = new StreamWriter(path, true))
{
sw.BaseStream.Seek(sw.BaseStream.Length, SeekOrigin.Begin);
byte[] buffer = _data;
if (_data.Length > 0)
Tracer.Warn(string.Format("Unhandled packet 0x{0:X2}", _data[0]));
buffer.ToFormattedString(buffer.Length, sw);
sw.WriteLine();
sw.WriteLine();
}
}
catch (Exception e)
{
Tracer.Error(e);
}
}
示例5: SaveTo
public static void SaveTo(string filename, MailAccess mailAccess) {
using (var streamWriter = new StreamWriter(filename, false, Encoding.UTF8)) {
streamWriter.WriteLine(mailAccess.Server);
streamWriter.WriteLine(mailAccess.Username);
streamWriter.WriteLine(mailAccess.Password);
}
}
示例6: 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();
}
示例7: 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;
}
}
}
}
示例8: SaveLastCode
private void SaveLastCode()
{
string filename = Path.Combine(localPath, "TestApp.os");
using (var writer = new StreamWriter(filename, false, Encoding.UTF8))
{
// первой строкой запишем имя открытого файла
writer.Write("//"); // знаки комментария, чтобы сохранить код правильным
writer.WriteLine(_currentDocPath);
// второй строкой - признак изменённости
writer.Write("//");
writer.WriteLine(_isModified);
args.Text = args.Text.TrimEnd('\r', '\n');
// запишем аргументы командной строки
writer.Write("//");
writer.WriteLine(args.LineCount);
for (var i = 0; i < args.LineCount; ++i )
{
string s = args.GetLineText(i).TrimEnd('\r', '\n');
writer.Write("//");
writer.WriteLine(s);
}
// и потом сам код
writer.Write(txtCode.Text);
}
}
示例9: exportCSV
public void exportCSV(string filename)
{
StreamWriter tw = new StreamWriter(filename);
tw.WriteLine("Filename;Key;Text");
string fn;
int i, j;
List<string> val;
string str;
for (i = 0; i < LTX_Texte.Count; i++)
{
fn = LTX_Texte[i].Key.ToLower().Replace(".ltx","");
val = LTX_Texte[i].Value;
for (j = 0; j < val.Count; j++)
{
str = prepareText(val[j], true);
if( str != "" )
tw.WriteLine(fn + ";" + j.ToString() + ";" + str);
}
}
for (i = 0; i < DTX_Texte.Count; i++)
{
fn = DTX_Texte[i].Key.ToLower().Replace(".dtx","");
val = DTX_Texte[i].Value;
for (j = 0; j < val.Count; j++)
{
str = prepareText(val[j], true);
if (str != "")
tw.WriteLine(fn + ";" + j.ToString() + ";" + str);
}
}
tw.Close();
}
示例10: Main
static void Main(string[] args)
{
var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var items = Directory.GetFiles(dir, "*.jpg").ToList();
items.AddRange(Directory.GetFiles(dir, "*.jpeg"));
items.AddRange(Directory.GetFiles(dir, "*.gif"));
items.AddRange(Directory.GetFiles(dir, "*.png"));
//rename all the filesthat are samples
const string SAM = "sample-";
foreach (var item in items.Select(x => Path.GetFileName(x)).Where(x => x.StartsWith(SAM, StringComparison.CurrentCultureIgnoreCase)))
{
var newName = Path.Combine(dir, item.Substring(SAM.Length, item.Length-SAM.Length));
var oldName = Path.Combine(dir, item);
if (!items.Contains(newName))
File.Copy(oldName, newName);
File.Delete(oldName);
}
using (var sw = new StreamWriter(Path.Combine(dir, "dir.js"), false))
{
sw.WriteLine("var IMAGES = [");
foreach (var item in items)
sw.WriteLine(" \"{0}\",", Path.GetFileName(item)); //seems we don't have to worry about the extra comma
sw.WriteLine("];");
}
}
示例11: Guardar
public void Guardar(Senial senial)
{
string _linea_dato = "";
string _fecha = senial.fecha_adquisicion.ToString ("yyyy MMMMM dd");
string _cantidad = senial.CantidadValores().ToString();
string _id = senial.Id.ToString ();
string _nombre = _ubicacion + "/" + _id + " - " + _fecha + ".txt";
try
{
using (StreamWriter _archivo = new StreamWriter(_nombre))
{
string cabecera = _id + ";" + _fecha + ";" + _cantidad + ";";
_archivo.WriteLine(cabecera);
for (int i = 1; i <= senial.CantidadValores(); i++)
{
_linea_dato = i.ToString() + ";" + senial.ObtenerValor(i - 1).ToString() + ";";
_archivo.WriteLine(_linea_dato);
}
this.Trazar(senial, "Se guardo la señal");
this.Auditar(senial, senial.GetType().ToString());
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
this.Trazar(senial, e.Message);
}
}
示例12: Log
public static void Log(LogFormat log, string fileName)
{
string filePath = string.Format("{0}{1}.csv", _logPath, fileName);
bool fileExists = false;
lock (lockMe)
{
if (File.Exists(filePath))
{
fileExists = true;
}
using (StreamWriter sw = new StreamWriter(filePath, true))
{
if (!fileExists)
{
sw.WriteLine("IN DATE TIME,FlawID,FlawName,Flaw Y value(M),Flaw X value(M),JobID,OUT DATA,TYPE,Flaw Y value(mm),Flaw X value(mm),OUT DATA TIME,STATUS");
}
string output = string.Format("{0},{1},,{2},{3},{4}",
log.InputDateTime,
log.InputData,
log.OutputData,
log.OutputDateTime,
log.Status);
sw.WriteLine(output);
sw.Close();
}
}
}
示例13: saveData
private void saveData()
{
TextWriter tw = new StreamWriter("penny.settings");
if (checkBox1.Checked) tw.WriteLine("Enabled");
else tw.WriteLine("Disabled");
tw.Close();
}
示例14: GenerateIntoClass
public static void GenerateIntoClass(
String targetFile, String @namespace, String classDeclaration, Action<StringBuilder> logic)
{
var buffer = new StringBuilder();
logic(buffer);
using (var targetFileWriter = new StreamWriter(targetFile))
{
targetFileWriter.WriteLine(Constants.CodegenDisclaimer);
targetFileWriter.WriteLine();
var textGeneratedIntoClass = typeof(Helpers).Assembly.ReadAllText("Truesight.TextGenerators.Core.TextGeneratedIntoClass.template");
textGeneratedIntoClass = textGeneratedIntoClass
.Replace("%NAMESPACE_NAME%", @namespace)
.Replace("%CLASS_DECLARATION%", classDeclaration)
.Replace("%GENERATED_TEXT%", buffer.ToString());
if (classDeclaration.Contains("enum") || classDeclaration.Contains("interface"))
{
textGeneratedIntoClass = textGeneratedIntoClass
.Replace(" [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]" + Environment.NewLine, "");
}
targetFileWriter.Write(textGeneratedIntoClass);
}
}
示例15: Delete
public bool Delete(Range range)
{
if (range.LineRange.Length == 0)
{
return true;
}
string fileContents = File.ReadAllText(_filename);
using (StringReader reader = new StringReader(fileContents))
using (TextWriter writer = new StreamWriter(File.Open(_filename, FileMode.Create)))
{
string lineText;
if (SeekTo(reader, writer, range, out lineText))
{
writer.WriteLine(lineText.Substring(0, range.LineRange.Start) + lineText.Substring(range.LineRange.Start + range.LineRange.Length));
}
lineText = reader.ReadLine();
while (lineText != null)
{
writer.WriteLine(lineText);
lineText = reader.ReadLine();
}
}
return true;
}