zoukankan      html  css  js  c++  java
  • 读写txt文件

    ------------------------写txt文件---------------------------------
    string fileName = Path.Combine(Application.StartupPath, @"History.txt");
    StreamWriter writer = new StreamWriter(fileName,false,Encoding.Default);
    foreach (string name in this.userName.AutoCompleteCustomSource)
    {
    writer.WriteLine(name);
    }
    writer.Flush();
    writer.Close();

    ------------------------读txt文件---------------------------------
    string fileName = Path.Combine(Application.StartupPath, @"History.txt");
    if (File.Exists(fileName))
    {
    StreamReader reader = new StreamReader(fileName,Encoding.Default);
    string name = reader.ReadLine();
    while (name != null)
    {
    this.userName.AutoCompleteCustomSource.Add(name);
    this.userName.Items.Add(name);
    name = reader.ReadLine();
    }
    reader.Close();
    }

  • 相关阅读:
    HackerRank
    HackerRank
    LeetCode "Kth Smallest Element in a BST"
    HackerRank
    HackerRank
    LeetCode "Roman to Integer"
    LeetCode "Integer to Roman"
    LeetCode "Majority Element II"
    HackerRank
    HackerRank
  • 原文地址:https://www.cnblogs.com/Devil1314/p/3246048.html
Copyright © 2011-2022 走看看