如何导入.txt文件,将数据存入数组。

解决方案 »

  1.   

    TextStreamer类。
    查下Msdn的相关内容。
    还有,问题说得太简单了。
      

  2.   

    http://blog.csdn.net/zhangjian01361/archive/2006/11/08/1373668.aspx
      

  3.   

    看msdn中關於File,Directory相關內容。
      

  4.   

    我这里有一个往数据库里导的代码,你只要把插数据那里改成插DATATABLE就OK了
    //******************<导入捆包表>********************
    else if(this.DropDownList1.SelectedIndex==1)
    {
    try
    {
    string pathName=this.File1.PostedFile.FileName;
    pathName=pathName.Substring(this.File1.PostedFile.FileName.LastIndexOf("\\")+1);
    string path=saveFile(pathName); StreamReader sr=new StreamReader(path);
    string oneLine;
    while((oneLine=sr.ReadLine())!=null)
    {
    string sql="insert into obj_postInfo values('"+oneLine+"')";
    data.RunNoneQuery(sql);
    }
    sr.Close();
    data.RunProc("P_InsertPostList");
    this.Response.Write("<script>alert('导入成功');</script>");
    }
    catch(System.Exception h)
    {
    log.Info(h.ToString());
    this.Response.Write("<script>alert('导入失败,请查看日志.');</script>");
    }
    finally
    {
    System.IO.Directory.Delete(path,true);
    }
    }