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();
}
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();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货