首页 > 代码库 > wince下写入数据到csv/txt文件中

wince下写入数据到csv/txt文件中

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;using SmartDeviceProject1.WebReference;using System.Reflection;namespace SmartDeviceProject1{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }                StreamWriter sw = null;        private void button1_Click(object sender, EventArgs e)        {            string path = @"\My Documents\入库.csv";//保存文件的路径            try            {                if (File.Exists(path))//如果文件已创建                {                    this.sw = File.AppendText(path);                    this.sw.WriteLine("叠加数据,123," + DateTime.Now.ToShortDateString());                }                else                {                    this.sw = new StreamWriter(path);//如果没有创建
this.sw.WriteLine("新建数据,789," + DateTime.Now.ToShortDateString()); } } catch (Exception ex)//异常处理 { MessageBox.Show(ex.Message); } finally { //清空缓冲区 this.sw.Flush(); //关闭流 this.sw.Close(); } } }}

vs2008测试正常。

wince下写入数据到csv/txt文件中