• c# 读写文件


            private void button1_Click(object sender, EventArgs e)

            {

                FileStream rfs,wfs;

                StreamWriter sw;

                StreamReader sr;

                //FileStream stream = new FileStream(@"E:mxh20141013addr111.csv", FileMode.Open);

                //StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("gb2312"));

                rfs = new FileStream(@"E:mxh20141013addr111.csv", FileMode.Open);

                sr = new StreamReader(rfs, Encoding.GetEncoding("gb2312"));

                wfs = new FileStream(@"E:mxh20141013addr222.txt", FileMode.Create, FileAccess.Write);

                sw = new StreamWriter(wfs,Encoding.GetEncoding("gb2312"));

                string sLine = "";

                string[] myList;

                while (sLine != null)

                {

                    sLine =sr.ReadLine();

                    if (sLine != null)

                    {

                        myList = sLine.Split(',');

                        sw.WriteLine("企业名称: "+myList[0]);

                        sw.WriteLine("发件地址: "+myList[1]);

                        sw.WriteLine("收件人: " + myList[2]);

                        sw.WriteLine();              

                    }

                }

                sw.Close();

                wfs.Close();

                sr.Close();

                rfs.Close();

                Close();

            }

  • 相关阅读:
    Linux编程之epoll
    Linux IO模式及 select、poll、epoll详解
    与程序员相关的CPU缓存知识
    JDK源码阅读-FileOutputStream
    JDK源码阅读-FileInputStream
    JDK源码阅读-ByteBuffer
    Java如何保证文件落盘?
    Linux/UNIX编程如何保证文件落盘
    JDK源码阅读-RandomAccessFile
    JDK源码阅读-FileDescriptor
  • 原文地址:https://www.cnblogs.com/xihong2014/p/4220998.html
Copyright © 2020-2023  润新知