System.IO.FileStream fs = new System.IO.FileStream("c:\\abc.bat",System.IO.FileMode.Create,System.IO.FileAccess.Write);
string s = "cls";
byte[] sByte = new byte[s.Length];
sByte = System.Text.UTF8Encoding.UTF8.GetBytes(s);
fs.Write(sByte,0,sByte.Length);
fs.Close();
解决方案 »
- CustomValidator 服务端验证不起作用
- 一个正则
- DataGridView 的 Shift+右键 多选代码 和Ctrl+右键 单选 要怎么写
- 求助,如何在表中指定列插入数值而其它列不受影响??
- 内存不足,咋整啊
- !求助“将 nvarchar 值 ''1','10','11','3'' 转换为数据类型为 int 的列时发生语法错误。”
- winform调试问题急救!!!在线等……
- 请问,如何用.Net实现枚举局域网中所有的SQL实例。
- 访问ACCESS数据库出错,谢谢
- 客户程序如何调用webservice查询数据库,再返回回来?
- 三个基础级问题
- 请问:在C#中怎么样才能获得已经截获的发生异常的代码的行号
//读取文件
private static void ReadFile()
{
using(FileStream fs = new FileStream("d:\\file1.bat",FileMode.Open,FileAccess.Read))
{
StreamReader sr = new StreamReader(fs,Encoding.Default);
Console.WriteLine(sr.ReadToEnd());
sr.Close();
}
}
把重新生成的bat写到文本文件中。
//写文件
private static void WriteFile()
{
using(FileStream fs = new FileStream("d:\\file1.bat",FileMode.Create,FileAccess.Write))
{
StreamWriter sr = new StreamWriter(fs);
StringBuilder sb = new StringBuilder();
for(int i=0;i<10000;i++)
sb.Append(i.ToString("0000")+",");
sr.Write(sb.ToString(0,sb.Length-1));
sr.Close();
}
}