微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

程序无法写入输出文件StreamWrite 问题

如何解决程序无法写入输出文件StreamWrite 问题

我是一名学生,我制作了一个程序,我可以从一个文件 (dimension.txt) 中读取数据,对其进行计算,然后将输出写入另一个文件 (result.txt) .程序可以读取dimension.txt,但不能写入输出文件result.txt。感谢任何可以提供帮助的人。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace AreaofRectangle
{
    class Program
    {
        static void Main(string[] args)
        {
            String path = AppDomain.CurrentDomain.BaseDirectory;
            StreamReader sr = new StreamReader(path + "/dimensions.txt");
            StreamWriter sw = new StreamWriter(path + "//result.txt");
            Console.WriteLine("Content of the File");
            sr.BaseStream.Seek(0,SeekOrigin.Begin);
            string str = sr.ReadLine();
            int rectangleCount = 1;
            while (str != null)
            {
                Console.WriteLine("\n\nRectangle " + rectangleCount);
                string[] number = str.Split(',');
                Console.WriteLine(str);
                string[] s = str.Split(',');

                int length = Int32.Parse(number[0]);
                int width = Int32.Parse(number[1]);
                int area = length * width;
                Console.WriteLine("Length: " + length);
                Console.WriteLine("Width: " + width);
                Console.WriteLine("Area: " + area);
                str = sr.ReadLine();
                rectangleCount++;
                sw.WriteLine("Length:" + length + " Width:" + width + " Area: " + " " + area);
            }
            Console.ReadKey();
            sw.Flush();
            sw.Close();
            sr.Close();
        }
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。