zoukankan      html  css  js  c++  java
  • 操纵txt文本文件

    txt文本文件(ticket.txt)的格式:
    666666,Alfred Lv,Resigned,06/24/2010 02:13:30 PM ZE8
    99999,Alfred Lv,Closed,06/24/2010 02:13:45 PM ZE8

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.IO;
    using System.Text;
    
    namespace WebApplication1
    {
        class FileUtilitity
        {
            public Ticket[] ReadFile()
            {
                string filename = "D:\\Ticket.txt";
                string[] Tickets = new string[4];
                List<Ticket> ticket = new List<Ticket>();
             
    
             
                //打开文件并显示其内容 
                StreamReader reader = null;
                try
                {
                    reader = new StreamReader(filename);
                    for (string line = reader.ReadLine(); !String.IsNullOrEmpty(line); line = reader.ReadLine())
                    {
                        Tickets = line.Split(',');
                        Ticket tmpTicket= new Ticket();
                        tmpTicket.TicketNo = Tickets[0];
                        tmpTicket.Author = Tickets[1];
                        tmpTicket.Status = Tickets[2];                    
                        tmpTicket.LastModified = Tickets[3];
                        ticket.Add(tmpTicket);                   
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                finally
                {
                    if (reader != null)
                        reader.Close();
                }
                return ticket.ToArray();
            }
    
            public void WriteFile(string s, string path)
            {
                FileStream fout = new FileStream(path, FileMode.Append, FileAccess.Write);
                StreamWriter brout = new StreamWriter(fout, Encoding.Default);
                brout.WriteLine(s);
                brout.Close();
            }
        }
    
        public class Ticket
        {
            public string TicketNo
            {
                get;
                set;
            }
    
            public string Status
            {
                get;
                set;
            }
    
            public string Author
            {
                get;
                set;
            }
            public string LastModified
            {
                get;
                set;
            }
        }
    }
    
    
  • 相关阅读:
    Linux文件/proc/net/tcp分析
    为什么系统调用会消耗较多资源
    为什么Linux默认页大小是4KB
    为什么Linux需要虚拟内存
    Make 命令教程
    关于同步的一点思考-下
    关于同步的一点思考-上
    Linux下的进程控制块(PCB)
    汇编语言基础:寄存器和系统调用
    内核栈与thread_info结构详解
  • 原文地址:https://www.cnblogs.com/mingle/p/CSharp_txt.html
Copyright © 2011-2022 走看看