void WriteStringsToText(CSting S[],int length)
{
CFile file;
file.Open("MyFile",CFile::modeCreate);
CString str;
str.Empty();
for(int i=0;i<length;i++)
{
str=str+S[i];
}
file.Write(str,str.GetLength());
file.Close();
}
{
CFile file;
file.Open("MyFile",CFile::modeCreate);
CString str;
str.Empty();
for(int i=0;i<length;i++)
{
str=str+S[i];
}
file.Write(str,str.GetLength());
file.Close();
}
解决方案 »
- 数据库查询问题 这样有错吗?
- c# 如何调用系统的邮件
- 请教Try 无法捕获httpwebrequest TimeOut错误
- c# winform中点击textbox,弹出日期对话框,选择某个日期,并显示在此textbox中
- 多个cheakbox组合的各种查询方法有没有简洁的代码
- IHTMLDOMChildrenCollection是个什么东东?
- C# 两个进程间传递消息出现乱码,如何解决
- asp.net,“错误抛出模式”在哪里设置?
- TextBox控件 会被百度卫士爆安全警告
- 最近学习报表ing,有些问题请教大家。
- 工具栏问题?
- 请大家推荐一个C#开发工具,最好具有自动关联功能!免费的最好~谢谢~~
{
Exception rtnExcept=new Exception("成功保存");
try
{
byte[] byteContain=StringToBytes(strContain);
FileStream fs;
if(blOverWrite)
fs=new FileStream(strFilePath,FileMode.Create);
else
fs=new FileStream(strFilePath,FileMode.Append,FileAccess.Write);
fs.Write(byteContain,0,byteContain.length);
}
catch(Exception e)
{
rtnExcept=e;
}
final
{
if(fs!=null)
fs.Close();
}
return rtnExcept;
}
public byte[] StringToBytes(string strSrc)
{
try
{
int byteLen=strSrc.length;
for(int i=0;i<strSrc.length;i++)
if(strSrc[i]>255)
byteLen++;
byte[] rtnBytes=new byte[byteLen];
for(int i=0,j=0;i<strSrc.length;i++)
if(strSrc[i]>255)
{
rtnBytes[j++]=Convert.ToByte(strSrc[i]>>8);
rtnBytes[j++]=Convert.ToByte(strSrc[i]&255);
}
else
{
rtnBytes[j++]=Convert.ToByte(strSrc[i]);
}
}
catch(Exception e)
{
throw(e);
}
return rtnBytes;
}
是不是只在*nix 系统中这个概念才有用呢?
另外,返回异常并不是抛出异常,抛出是使用THROW语句实现,在该函数的调用过程中还是会被捕捉到,而我的返回异常是不会被TRY检测到。
处理异常很简单,最简单的使用方法就是异常转换成STRING,就知道其内容了,另外可以查看相关资料,而且异常有很多继承的类型。