小编Zin*_*ium的帖子

如何关闭已读取的文件

所以我试图关闭一个已经打开的文件(transactions.txt),我曾经将其读入文本框,现在我想保存回该文件,但是问题调试表明该文件正在使用中,所以我需要找到一种关闭它的方法。谁能帮我这个?谢谢!

        SearchID = textBox1.Text;
        string ID = SearchID.ToString();
        bool idFound = false;
        int count = 0;

        foreach (var line in File.ReadLines("transactions.txt"))
        {

            //listView1.Items.Add(line);

            if (line.Contains(ID))
            {
                idFound = true;
            }

            //Displays Transactions if the variable SearchID is found.
            if (idFound && count < 8)
            {
                textBox2.Text += line + "\r\n";
                count++;

            }
        }
    }

    private void SaveEditedTransaction()
    {
        SearchID = textBox1.Text;
        string ID = SearchID.ToString();
        bool idFound = false;
        int count = 0;

        foreach (var lines in File.ReadLines("transactions.txt"))
        {

            //listView1.Items.Add(line); …
Run Code Online (Sandbox Code Playgroud)

c# streamwriter streamreader

0
推荐指数
1
解决办法
8995
查看次数

标签 统计

c# ×1

streamreader ×1

streamwriter ×1