这行代码看不懂!

tu_quan_ren 2009-07-05 06:09:10
1.正在学习制作一个,新闻阅读器.在写"用户配置管理类"(class ProfileManager)时,遇到问题了.
2.FileStream在声明实例时,其构造函数的参数应该是“文件路径”和“文件访问方式”
FileStream fs = new FileStream(string path,FileMode Mode);
可是下面的代码:
FileStream fs = new FileStream("user.profile",FileMode.Create)
这个"user.profile"??没有这样的后缀名的文件吧??这样做有什么用意吗?

3.用户配置类(class Profile):

using System;
using System.Collections.Generic;
using System.Text;

namespace MyNewsReader
{
class Profile
{
public Profile() { }

//频道集合
public List<FeedBase> Feeds = new List<FeedBase>();


//刷新间隔
public TimeSpan IntervalToRefresh;

}


}



4.用户配置管理类:


class ProfileManager
{

public Profile Profile = new Profile();

public ProfileManager()
{
//Init();
}

//默认频道设置
private void ChannelReset()
{
Profile.Feeds.Clear();

}

//保存用户配置信息
public void Save()
{

FileStream fs = new FileStream("user.profile",FileMode.Create);//文件流的参数应该是(string path,FileMode Mode)
StreamWriter sw = new StreamWriter(fs);

//写入频道总数
sw.WriteLine(Profile.Feeds.Count);

foreach(FeedBase feed in Profile.Feeds)
{
////判断频道类型
if (feed is AtomFeed)
{
sw.WriteLine("Atom");//写入频道类型

}
if (feed is RssFeed)
{
sw.WriteLine("RSS");

}
//Feed 的三个基本信息每行存一个
sw.WriteLine(feed.DisplayName);
sw.WriteLine(feed.Url);
sw.WriteLine(feed.Description);
}

sw.Close();
fs.Close();
}


...全文
25 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tu_quan_ren 2009-07-05
  • 打赏
  • 举报
回复
欧,谢谢!
OnlyAlone 2009-07-05
  • 打赏
  • 举报
回复
创建文件啊,什么扩展名不可以?想用什么扩展名就用什么扩展名,自己定的

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧