zoukankan      html  css  js  c++  java
  • 文件操作

    /// <summary>
           
    /// 将存贮在文本文件中的数据绑定到DropDownList中  test,test
           
    /// </summary>
           
    /// <param name="drdlst">下拉菜单</param>
           
    /// <param name="filePath">虚拟路径</param>
            public void Drdlst_BindDataByTxt1(DropDownList drdlst, string filePath)
            {
               
    string fileName = HttpContext.Current.Server.MapPath(filePath);
               
    string content = "";
                StreamReader sr
    = null;
               
    try
                {
                   
    //打开文件并显示其内容
                    sr = new StreamReader(fileName, System.Text.Encoding.Default);
                   
    for (string line = sr.ReadLine(); line != null; line = sr.ReadLine())
                    {
                        content
    += line.ToString();
                    }
                   
    string[] arr = content.Split(',');
                   
    for (int i = 0; i < arr.Length; i++)
                    {
                        ListItem li
    = new ListItem();
                        li.Text
    = arr[i].ToString();
                        li.Value
    = arr[i].ToString();
                        drdlst.Items.Add(li);
                    }
                }
               
    catch (IOException ee)
                {
                    HttpContext.Current.Response.Write(
    "<script>alert(" + ee.Message + ")</script>");
                }
               
    finally
                {
                   
    if (sr != null)
                    {
                        sr.Close();
                    }
                }
            }

           
    /// <summary>
           
    /// 获取txt中信息
           
    /// </summary>
           
    /// <param name="filePath">虚拟路径</param>
           
    /// <returns></returns>
            public string GetTxtInfo(string filePath)
            {
               
    string fileName = HttpContext.Current.Server.MapPath(filePath);
               
    string str = "";
                StreamReader sr
    = null;
               
    try
                {
                    sr
    = new StreamReader(fileName, System.Text.Encoding.Default);
                   
    for (string line = sr.ReadLine(); line != null; line = sr.ReadLine())
                    {
                        str
    += line.ToString();
                    }
                }
               
    catch (IOException ee)
                {
                    HttpContext.Current.Response.Write(
    "<script>alert(" + ee.Message + ")</script>");
                }
               
    finally
                {
                   
    if (sr != null)
                    {
                        sr.Close();
                    }
                }

               
    return str;
            }

           
    /// <summary>
           
    /// 保存数据到txt中
           
    /// </summary>
           
    /// <param name="str">要保存的数据</param>
           
    /// <param name="filePath">虚拟路径</param>
            public void SaveTxtInfo(string str, string filePath)
            {
               
    string fileName = HttpContext.Current.Server.MapPath(filePath);
                StreamWriter sw
    = null;
                FileStream oFileStream
    = null;
               
    try
                {
                   
    if (!System.IO.File.Exists(fileName))
                    {
                        oFileStream
    = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                    }
                   
    else
                    {
                        oFileStream
    = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
                    }

                    sw
    = new StreamWriter(oFileStream, Encoding.Default);
                    sw.Write(str);
                    sw.WriteLine();
                }
               
    catch (IOException ee)
                {
                    HttpContext.Current.Response.Write(
    "<script>alert(" + ee.Message + ")</script>");
                }
               
    finally
                {
                   
    if (sw != null)
                    {
                        sw.Close();
                        oFileStream.Close();
                    }
                }
            }

  • 相关阅读:
    Activiti工作流引擎简介
    关于使用sklearn进行数据预处理 —— 归一化/标准化/正则化
    关于 sklearn.decomposition.KernelPCA的简单介绍
    numpy.mean和numpy.random.multivariate_normal(依据均值和协方差生成数据,提醒:计算协方差别忘了转置)
    没办法,SVD就讲的这么好
    SVD实例
    奇异值分解(SVD)实例,将不重要的特征值改为0,原X基本保持不变
    奇异值分解(SVD)详解
    numpy和matlab计算协方差矩阵的不同(matlab是标准的,numpy相当于转置后计算)
    特征值和特征向量的几何意义、计算及其性质(一个变换(或者说矩阵)的特征向量就是这样一种向量,它经过这种特定的变换后保持方向不变,只是进行长度上的伸缩而已)
  • 原文地址:https://www.cnblogs.com/liufei88866/p/1762860.html
Copyright © 2011-2022 走看看