本文整理汇总了C#中System.IO.StreamWriter.Write方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StreamWriter.Write方法的具体用法?C# System.IO.StreamWriter.Write怎么用?C# System.IO.StreamWriter.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamWriter
的用法示例。
在下文中一共展示了System.IO.StreamWriter.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
}
示例2: Save
public void Save(string filename)
{
//@todo validatoin
System.IO.StreamWriter writer = new System.IO.StreamWriter(filename, false, Encoding.ASCII);
writer.WriteLine("TITLE " + Title);
writer.WriteLine("");
writer.WriteLine("LUT_3D_SIZE " + Dimension.ToString());
writer.WriteLine("DOMAIN_MIN 0.0 0.0 0.0");
writer.WriteLine("DOMAIN_MAX 1.0 1.0 1.0");
writer.WriteLine("");
for (int b = 0; b < Dimension; b++)
for (int g = 0; g < Dimension; g++)
for (int r = 0; r < Dimension; r++)
{
writer.Write(string.Format("{0:0.00000}", red[r, g, b]));
writer.Write("\t");
writer.Write(string.Format("{0:0.00000}", green[r, g, b]));
writer.Write("\t");
writer.Write(string.Format("{0:0.00000}", blue[r, g, b]));
writer.WriteLine("");
}
writer.Flush();
writer.Close();
}
示例3: BuildDungeon
public void BuildDungeon()
{
RDG.Dungeon dungeon = new RDG.Dungeon(80, 80, 80);
System.IO.StreamWriter fout = new System.IO.StreamWriter("C:\\Test.txt");
List<RDG.Room> roomList;
for (int r = 0; r < dungeon.Height; r++)
{
for (int c = 0; c < dungeon.Height; c++)
{
RDG.Dungeon.Coordinates coords = new RDG.Dungeon.Coordinates(r,c);
if (dungeon.Map.TryGetValue(coords, out roomList))
{
fout.Write(roomList.Count);
}
else
{
fout.Write("0");
}
}
fout.WriteLine();
}
fout.Flush();
fout.Close();
}
示例4: writeGroup
/// <summary> <p>Creates source code for a Group and returns a GroupDef object that
/// describes the Group's name, optionality, repeatability. The source
/// code is written under the given directory.</p>
/// <p>The structures list may contain [] and {} pairs representing
/// nested groups and their optionality and repeastability. In these cases
/// this method is called recursively.</p>
/// <p>If the given structures list begins and ends with repetition and/or
/// optionality markers the repetition and optionality of the returned
/// GroupDef are set accordingly.</p>
/// </summary>
/// <param name="structures">a list of the structures that comprise this group - must
/// be at least 2 long
/// </param>
/// <param name="baseDirectory">the directory to which files should be written
/// </param>
/// <param name="message">the message to which this group belongs
/// </param>
/// <throws> HL7Exception if the repetition and optionality markers are not </throws>
/// <summary> properly nested.
/// </summary>
public static NuGenGroupDef writeGroup(NuGenStructureDef[] structures, System.String groupName, System.String baseDirectory, System.String version, System.String message)
{
//make base directory
if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
{
baseDirectory = baseDirectory + "/";
}
System.IO.FileInfo targetDir = NuGenSourceGenerator.makeDirectory(baseDirectory + NuGenSourceGenerator.getVersionPackagePath(version) + "group");
NuGenGroupDef group = getGroupDef(structures, groupName, baseDirectory, version, message);
System.IO.StreamWriter out_Renamed = new System.IO.StreamWriter(new System.IO.StreamWriter(targetDir.FullName + "/" + group.Name + ".java", false, System.Text.Encoding.Default).BaseStream, new System.IO.StreamWriter(targetDir.FullName + "/" + group.Name + ".java", false, System.Text.Encoding.Default).Encoding);
out_Renamed.Write(makePreamble(group, version));
out_Renamed.Write(makeConstructor(group, version));
NuGenStructureDef[] shallow = group.Structures;
for (int i = 0; i < shallow.Length; i++)
{
out_Renamed.Write(makeAccessor(group, i));
}
out_Renamed.Write("}\r\n");
out_Renamed.Flush();
out_Renamed.Close();
return group;
}
示例5: GetConfig
internal void GetConfig()
{
lb0: ;
if (System.IO.File.Exists(Environment.CurrentDirectory + "\\config.cfg"))
{
StringBuilder sb = new StringBuilder(1024);
GetPrivateProfileString("mssql", "server", "", sb, sb.MaxCapacity, Environment.CurrentDirectory + "\\config.cfg"); ;
datasource = sb.ToString();
sb.Clear();
GetPrivateProfileString("mssql", "user", "", sb, sb.MaxCapacity, Environment.CurrentDirectory + "\\config.cfg"); ;
userid = sb.ToString();
sb.Clear();
GetPrivateProfileString("mssql", "password", "", sb, sb.MaxCapacity, Environment.CurrentDirectory + "\\config.cfg"); ;
password = sb.ToString();
sb.Clear();
}
else
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(Environment.CurrentDirectory + "\\config.cfg", true);
sw.Write("[MSSQL]" + Environment.NewLine);
sw.Write("server=(local)" + Environment.NewLine);
sw.Write("user=sa" + Environment.NewLine);
sw.Write("password=" + Environment.NewLine);
sw.Close();
goto lb0;
}
}
示例6: updateInventory
// Export to file
public void updateInventory(List<List<string>> lst)
{
inventory = lst;
String directory = Environment.CurrentDirectory + "\\productInventory.txt";
System.IO.StreamWriter file2 = new System.IO.StreamWriter(directory);
foreach(List<String> lt in inventory)
{
//prodId
file2.Write("{0},", lt[0]);
//product name
for (int i = 3; i < lt.Count; i++)
{
if(i == lt.Count - 1)
{
file2.Write(lt[i]);
}
else
{
file2.Write(lt[i] + " ");
}
}
//amount and cost
file2.Write(",{0},{1}", lt[1], lt[2]);
file2.WriteLine();
}
file2.Close();
}
示例7: 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.");
}
}
示例8: Main
static void Main(string[] args)
{
double start = -4;
double end = 6;
double factor = 65535 / Math.Exp(end);
int steps = 100;
double step = (end - start) / (steps - 1);
int i;
int value;
System.IO.StreamWriter file = new System.IO.StreamWriter(@"logvec.h");
System.IO.StreamWriter file2 = new System.IO.StreamWriter(@"logvec.txt");
file.Write("static const int logvec[] = { 0x0000,");
for (i = 0; i < 100; i++)
{
if ((i % 10) == 0)
{
file.WriteLine();
file.Write("\t");
}
value = (int)Math.Floor(Math.Exp(start) * factor);
start += step;
file2.Write("{0}, ", value);
file.Write ("0x{0:X4}, ", value);
}
file.WriteLine();
file.WriteLine("};");
file.Close();
file2.Close();
}
示例9: WriteToFile
public void WriteToFile()
{
using (System.IO.StreamWriter file =
new System.IO.StreamWriter(@"C:\capstone\output.nex"))
{
file.WriteLine("#NEXUS");
file.WriteLine("BEGIN TAXA;");
file.WriteLine("Dimensions NTax=" + nexusOb.T.taxa.Count);
file.Write("TaxLabels ");
foreach (string taxon in nexusOb.T.taxa)
{
file.Write(taxon + " ");
}
file.WriteLine();
file.WriteLine("END;");
file.WriteLine("BEGIN CHARACTERS;");
file.WriteLine(@"DIMENSIONS NChar=""");
file.WriteLine("MATRIX");
foreach (Sequence s in App.f.C.sequences)
{
file.WriteLine(s.name + " " + s.characters);
}
file.WriteLine(";");
file.WriteLine("END;");
}
}
示例10: FlowStatics
public static void FlowStatics()
{
System.IO.StreamWriter sw = new System.IO.StreamWriter("log.txt", false);
DataClasses1DataContext mydb = new DataClasses1DataContext(common.connString);
var message = mydb.LA_update1.Select(e => e.ip_version_MsgType).Distinct();
Dictionary<string, int> myDic = new Dictionary<string, int>();
foreach (string m in message)
{
myDic.Add(m, 0);
Console.Write(m + "--------------------");
Console.WriteLine(0);
sw.Write(m + "--------------------");
sw.WriteLine(0);
}
sw.Flush();
List<string> startmessage = new List<string>();
startmessage.Add("DTAP MM.Location Updating Request");
startmessage.Add("DTAP MM.CM Service Request");
startmessage.Add("DTAP RR.Paging Response");
startmessage.Add("BSSMAP.Handover Request");
foreach (var start in startmessage)
{
Dictionary<string, int> newDic = new Dictionary<string, int>();
foreach (KeyValuePair<string, int> pair in myDic)
newDic.Add(pair.Key, 0);
var a = from p in mydb.LA_update1
where p.ip_version_MsgType == start
select p.opcdpcsccp;
foreach (var b in a)
{
foreach (KeyValuePair<string, int> kvp in myDic)
{
var c = mydb.LA_update1.Where(e => e.opcdpcsccp == b).Where(e => e.ip_version_MsgType == kvp.Key).FirstOrDefault();
if (c != null)
newDic[kvp.Key] = newDic[kvp.Key] + 1;
}
}
foreach (var m in newDic.OrderByDescending(e => e.Value))
{
Console.Write(m.Key+"--------------------");
Console.WriteLine(m.Value);
sw.Write(m.Key + "--------------------");
sw.WriteLine(m.Value);
}
sw.Flush();
}
sw.Close();
}
示例11: button1_Click
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog o = new OpenFileDialog();
o.ShowDialog();
int p = o.FileName.IndexOf('.');
char[] OutputFilename = new char[o.FileName.Length + 1];
o.FileName.CopyTo(0, OutputFilename, 0, o.FileName.Length - 1);
OutputFilename[o.FileName.Length-3] = 'h';
OutputFilename[o.FileName.Length-2] = 'e';
OutputFilename[o.FileName.Length-1] = 'x';
string strOutputFilename = new string(OutputFilename, 0, OutputFilename.Length - 1);
System.IO.TextWriter f = new System.IO.StreamWriter(strOutputFilename);
System.Drawing.Bitmap bmp = new Bitmap(o.FileName);
int r = 0;
int c = 0;
while (r < bmp.Height)
{
c = 0;
while (c < bmp.Width)
{
Color rgb = bmp.GetPixel(c, r);
/*
First character (:) = Start of a record
Next two characters = Record length (in this example, 10h)
Next four characters = Load address (in this example, 0080h)
Next two characters = Record type
Remaining characters = Actual data
Last two characters = Checksum (i.e., sum of all bytes + checksum = 00)
*/
int RecordLength = 2;
int RecordType = 0;
float oatR = ((float)rgb.R )/ 32,
oatG = ((float)rgb.G )/ 32,
oatB = ((float)rgb.B )/ 32;
int intR = (int)oatR + ((oatR - (int)oatR) >= .5 ? 1 : 0),
intG = (int)oatG + ((oatG - (int)oatG) >= .5 ? 1 : 0),
intB = (int)oatB + ((oatB - (int)oatB) >= .5 ? 1 : 0);
intR = intR > 7 ? 7 : intR;
intG = intG > 7 ? 7 : intG;
intB = intB > 7 ? 7 : intB;
int Data = ( (intR << 6) | ( (intG & 7) << 3) | (intB & 7));
int LoadAddress = c + bmp.Width * r;
int Checksum = (256 - (RecordLength + (LoadAddress >> 8) + (LoadAddress & 255) + RecordType + (Data >> 8) + Data & 255)) & 0xFF;
string strRecordLength = String.Format("{0:X2}", RecordLength),
strLoadAddress = String.Format("{0:X4}", LoadAddress),
strRecordType = String.Format("{0:X2}", RecordType),
strData = String.Format("{0:X4}", Data),
strChecksum = String.Format("{0:X2}", Checksum);
f.Write(":" + strRecordLength + strLoadAddress + strRecordType + strData + strChecksum + "\n");
++c;
}
++r;
}
f.Write(":00000001FF");
f.Close();
}
示例12: escribir_arbol
public void escribir_arbol()
{
escribir = new System.IO.StreamWriter("C:\\Practica1\\ast.dot");
escribir.Write("digraph ast{\n");
graficar_arbol(root);
escribir.Write("\n}");
escribir.Close();
generar_arbol();
}
示例13: ExportStudyToCSVOneFile
public void ExportStudyToCSVOneFile(DatabaseControl db, Study study, string filename)
{
string header = "StudyName,SubjectID,SessionName,SessionDate,TrialName,SessionSync1.Onset,SessionSync1.Offset,SessionSync2.Onset,SessionSync2.Offset,";
for (int i = 0; i < 15; i++)
{
header += string.Format("Sensor{0}.ID,Sensor{0}.Time,Sensor{0}.Switch,Sensor{0}.X,Sensor{0}.Y,Sensor{0}.Z,Sensor{0}.Pitch,Sensor{0}.Roll,Sensor{0}.Yaw,Sensor{0}.quality,", i);
}
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@filename))
{
file.Write(header + "\n");
foreach (Subject sub in db.GetSubjects(study))
{
foreach (Session sess in db.GetSessions(sub))
{
foreach (Trial trial in db.GetTrials(sess))
{
Console.WriteLine("Dumping trial : " + trial.name);
status = string.Format("{0} - {1} - {2} - {3}", study.name, sub.id, sess.name, trial.name);
int total = db.GetSensorReadings(trial).Count();
int count = 0;
foreach (SensorReading pt in db.GetSensorReadings(trial))
{
count++;
percent = Convert.ToInt32(Math.Ceiling((float)count / (float)total * 100.0));
Sensor[] sensors = pt.sensors;
// Append study/sub/sess/trial data
file.Write(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}", study.name, sub.id, sess.name, sess.tdate, trial.name, sess.sync1_on, sess.sync1_off, sess.sync2_on, sess.sync2_off));
for (int i = 0; i < sensors.Length; i++)
{
if (sensors[i].active == 1)
{
// Append sensor data whether sensor is active or not
file.Write(string.Format(",{0},{9},{1},{2:0.00},{3:0.00},{4:0.00},{5:0.00},{6:0.00},{7:0.00},{8}",
i, sensors[i].button, sensors[i].x, sensors[i].y, sensors[i].z, sensors[i].pitch, sensors[i].roll, sensors[i].yaw, sensors[i].quality, sensors[i].time));
}
else
{
// If the sensor wasn't active then append a blank filler
file.Write(",,,,,,,,,,");
}
}
file.Write("\n");
}
percent = 0;
}
}
}
}
}
示例14: 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 : ",");
}
}
}
}
示例15: writeDataAndHeaderIntoFile
public void writeDataAndHeaderIntoFile(string fileName)
{
using (System.IO.StreamWriter writeFile = new System.IO.StreamWriter(fileName))
{
int totalRows = Math.Max(fileData[0].data.Length + 1,headerStrings.Length);
for (int i = 0; i < totalRows; i++)
{
//write header columns
if (i <= headerStrings.GetUpperBound(0))
{
writeFile.Write(headerStrings[i]);
writeFile.Write(",");
}
else
{
writeFile.Write(",,");
}
//write data
if (i == 0)
{
foreach (singleColData sCol in fileData)
{
writeFile.Write(sCol.name);
writeFile.Write(",");
}
}
else
{
foreach (singleColData sCol in fileData)
{
//Write data if the index is still within the array length
if ((i - 1) < sCol.data.Length)
{
double temp = sCol.data[i - 1];
if (temp <= 10000 || temp >= 0.001)
{
writeFile.Write(temp.ToString("G"));
writeFile.Write(",");
}
else
{
writeFile.Write(temp.ToString("E"));
writeFile.Write(",");
}
}
}
}
writeFile.WriteLine();
}
}
}