如何在c#中将同一文件的文本写入多个文本文件

时间:2014-04-21 11:15:18

标签: c#

我有一个11字节的文本文件现在我要分割并将文本写入多个文件,每个文件说2个字节,最后一个文件3个如何使用c#

现在这里是我的代码,它将整个文件写入一个新文件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
             this.Text = textBox1.Text;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var fileName = Text;
            FileInfo fi = new FileInfo(fileName);
            var size = fi.Length;
            int i = Convert.ToInt32(size);
            int j = Convert.ToInt32(comboBox1.SelectedItem);
            decimal ireminder = (decimal)i % j;

            MessageBox.Show(ireminder.ToString());
            StreamReader sr = new StreamReader(Text);
            var line = sr.ReadLine();
            StreamWriter sw = new StreamWriter("D:\\Test.txt");
            sw.WriteLine(line);
            sw.Close();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

    }
}

0 个答案:

没有答案