使用Filestream文件流和StreamWriter对象

来源:百度知道 编辑:UC知道 时间:2024/06/25 04:52:41
创建控制台程序,添加Book类,包含属性书名(string),出版社(string),作者(string),价格(double).
创建几个图书对象,将他们的属性值打印到文本文件.
提示:
(1)使用Filestream文件流和StreamWriter对象.
(2)多本书,需要循环输入

下面就是你要的
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
StreamWriter streamWriter = new StreamWriter(@"D:\Book.txt",true);
Book book = new Book();
while (true)
{
Console.WriteLine("请输入书名:");
book.Name = Console.ReadLine();
Console.WriteLine("请输入出版社:");
book.Publisher = Console.ReadLine();
Console.WriteLine("请输入作者:");
book.Author = Console.ReadLine();
Console.WriteLine("请输入价格:");
book.Cost = Convert.ToDouble(Console.ReadLine());
Console.Clear();
streamWriter.Write