问题描述
我是一名学生,我制作了一个程序,我可以从一个文件 (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 (将#修改为@)