1、使用ASP网页,输出结果直接复制粘贴到新文本文件里
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //string str = "aaa,bbb,ccc,ddd"; // 读取文件的源路径及其读取流 string strReadFilePath = @"G:\数据001.txt"; StreamReader srReadFile = new StreamReader(strReadFilePath); // 写入文件的源路径及其写入流 string strWriteFilePath = @"G:\数据002.txt"; StreamWriter swWriteFile = File.CreateText(strWriteFilePath); // 读取流直至文件末尾结束 while (!srReadFile.EndOfStream) { string str = srReadFile.ReadLine(); //读取每行数据 //Console.WriteLine(strReadLine); //屏幕打印每行数据 string[] sArray = str.Split(','); foreach (string i in sArray) //Response.Write(i.ToString() + "<br>"); swWriteFile.WriteLine(i.ToString()); //写入读取的每行数据 } // 关闭读取流文件 srReadFile.Close(); swWriteFile.Close(); } }
2、使用WinForm窗体控制动态参数,直接输出结果到新文本文件
namespace WindowsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // 统计写入(读取的行数) int WriteRows = 0; //string str = "aaa,bbb,ccc,ddd"; // 读取文件的源路径及其读取流 string strReadFilePath = textBox1.Text.ToString(); StreamReader srReadFile = new StreamReader(strReadFilePath); // 写入文件的源路径及其写入流 string strWriteFilePath = textBox2.Text.ToString(); StreamWriter swWriteFile = File.CreateText(strWriteFilePath); // 读取流直至文件末尾结束 while (!srReadFile.EndOfStream) { string str = srReadFile.ReadLine(); //读取每行数据 //Console.WriteLine(strReadLine); //屏幕打印每行数据 string[] sArray = str.Split(textBox3.Text.ToCharArray()); //foreach (string i in sArray) //Response.Write(i.ToString() + "<br>"); //swWriteFile.WriteLine(i.ToString()); //写入读取的每行数据 //++WriteRows; //统计写入(读取)的数据行数 for (int i = 0; i < sArray.Length; i++) { swWriteFile.WriteLine(sArray[i].ToString()); //写入读取的每行数据 WriteRows=i+1; //统计写入(读取)的数据行数 } } label4.Visible = true; label4.Text = WriteRows.ToString(); // 关闭读取流文件 srReadFile.Close(); swWriteFile.Close(); } } }