我要写入到文本文件,变成这样的形式:
10.100.182.89
10.100.182.90
请教该如何写。。。
我菜鸟。。打家多帮助哈!谢谢啦
14 个解决方案
#1
System.IO.File.WriteAllLines(string path,string[]Data)
#2
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine("10.100.182.89");
sw.WriteLine("10.100.182.90 ");
}
{
sw.WriteLine("10.100.182.89");
sw.WriteLine("10.100.182.90 ");
}
#3
那就按行写呗
#4
StreamWriter writer = new StreamWriter(filepath);
writer.Write(string.Concat("10.100.182.89",Environment.NewLine));
writer.Write(string.Concat("10.100.182.90",Environment.NewLine));
writer.Close();
writer.Write(string.Concat("10.100.182.89",Environment.NewLine));
writer.Write(string.Concat("10.100.182.90",Environment.NewLine));
writer.Close();
#5
StreamWriter my_writer = null;
string txtstr="10.100.182.89\r\n10.100.182.90"
my_writer = new StreamWriter(@"d:\abc.txt", true, System.Text.Encoding.Default);
my_writer.Write(txtstr);
my_writer.Flush();
string txtstr="10.100.182.89\r\n10.100.182.90"
my_writer = new StreamWriter(@"d:\abc.txt", true, System.Text.Encoding.Default);
my_writer.Write(txtstr);
my_writer.Flush();
#6
System.IO.StreamWriter fs = new System.IO.StreamWriter("C:\aa.txt")
fs.WriteLine("10.100.182.89");
fs.WriteLine("10.100.182.90");
fs.flush();
#7
static void Main(string[] args)
{
string[] strs = new string[]
{
"10.100.182.89",
"10.100.182.90"
};
using (FileStream fileStream = File.OpenWrite("C:\\test.txt"))
{
using (StreamWriter writer = new StreamWriter(fileStream))
{
foreach (string s in strs)
{
writer.WriteLine(s);
}
writer.Close();
}
}
}
#8
每个字符串后面 + @"\r\n"然后在写入
#9
直接用StreamWriter更方便,上面我绕弯了。
static void Main(string[] args)
{
string[] strs = new string[]
{
"10.100.182.89",
"10.100.182.90"
};
using (StreamWriter writer = new StreamWriter("C:\\test.txt"))
{
foreach (string s in strs)
{
writer.WriteLine(s);
}
writer.Close();
}
}
#10
string[] s={"10.100.182.89","10.100.182.90"};
StreamWriter swFromFile = new StreamWriter(logFile);
for(int i=0;i<s.Length;++i)
swFromFile.WriteLine(s[i]);
swFromFile.Close();
StreamWriter swFromFile = new StreamWriter(logFile);
for(int i=0;i<s.Length;++i)
swFromFile.WriteLine(s[i]);
swFromFile.Close();
#11
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine("10.100.182.89");
sw.WriteLine("10.100.182.90 ");
}
{
sw.WriteLine("10.100.182.89");
sw.WriteLine("10.100.182.90 ");
}
#12
非常感谢各位。。。各位的给的方法非常好用。。谢谢大家。。。
#13
卡卡那看~~~
#14
学习了
#1
System.IO.File.WriteAllLines(string path,string[]Data)
#2
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine("10.100.182.89");
sw.WriteLine("10.100.182.90 ");
}
{
sw.WriteLine("10.100.182.89");
sw.WriteLine("10.100.182.90 ");
}
#3
那就按行写呗
#4
StreamWriter writer = new StreamWriter(filepath);
writer.Write(string.Concat("10.100.182.89",Environment.NewLine));
writer.Write(string.Concat("10.100.182.90",Environment.NewLine));
writer.Close();
writer.Write(string.Concat("10.100.182.89",Environment.NewLine));
writer.Write(string.Concat("10.100.182.90",Environment.NewLine));
writer.Close();
#5
StreamWriter my_writer = null;
string txtstr="10.100.182.89\r\n10.100.182.90"
my_writer = new StreamWriter(@"d:\abc.txt", true, System.Text.Encoding.Default);
my_writer.Write(txtstr);
my_writer.Flush();
string txtstr="10.100.182.89\r\n10.100.182.90"
my_writer = new StreamWriter(@"d:\abc.txt", true, System.Text.Encoding.Default);
my_writer.Write(txtstr);
my_writer.Flush();
#6
System.IO.StreamWriter fs = new System.IO.StreamWriter("C:\aa.txt")
fs.WriteLine("10.100.182.89");
fs.WriteLine("10.100.182.90");
fs.flush();
#7
static void Main(string[] args)
{
string[] strs = new string[]
{
"10.100.182.89",
"10.100.182.90"
};
using (FileStream fileStream = File.OpenWrite("C:\\test.txt"))
{
using (StreamWriter writer = new StreamWriter(fileStream))
{
foreach (string s in strs)
{
writer.WriteLine(s);
}
writer.Close();
}
}
}
#8
每个字符串后面 + @"\r\n"然后在写入
#9
直接用StreamWriter更方便,上面我绕弯了。
static void Main(string[] args)
{
string[] strs = new string[]
{
"10.100.182.89",
"10.100.182.90"
};
using (StreamWriter writer = new StreamWriter("C:\\test.txt"))
{
foreach (string s in strs)
{
writer.WriteLine(s);
}
writer.Close();
}
}
#10
string[] s={"10.100.182.89","10.100.182.90"};
StreamWriter swFromFile = new StreamWriter(logFile);
for(int i=0;i<s.Length;++i)
swFromFile.WriteLine(s[i]);
swFromFile.Close();
StreamWriter swFromFile = new StreamWriter(logFile);
for(int i=0;i<s.Length;++i)
swFromFile.WriteLine(s[i]);
swFromFile.Close();
#11
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine("10.100.182.89");
sw.WriteLine("10.100.182.90 ");
}
{
sw.WriteLine("10.100.182.89");
sw.WriteLine("10.100.182.90 ");
}
#12
非常感谢各位。。。各位的给的方法非常好用。。谢谢大家。。。
#13
卡卡那看~~~
#14
学习了