public void WriteFile(string str1, string str2)
{
try
{
StreamWriter sw = new StreamWriter(str2);
sw.WriteLine(str1);
sw.Flush();
sw.Close();
}
catch
{
MessageBox.Show("我**!");
}
//StreamWriter sr;
//sr = File.CreateText(str2);
//sr.WriteLine(str1);
//sr.Close();
}很奇怪很无奈,软件随机启动,上面函数创建文本文件无效,文件存在他不覆盖,文件不存在他创建不出来,又不报错不走catch!!!软件关闭在打开就正常了!!!!!!????
{
try
{
StreamWriter sw = new StreamWriter(str2);
sw.WriteLine(str1);
sw.Flush();
sw.Close();
}
catch
{
MessageBox.Show("我**!");
}
//StreamWriter sr;
//sr = File.CreateText(str2);
//sr.WriteLine(str1);
//sr.Close();
}很奇怪很无奈,软件随机启动,上面函数创建文本文件无效,文件存在他不覆盖,文件不存在他创建不出来,又不报错不走catch!!!软件关闭在打开就正常了!!!!!!????
解决方案 »
- 这个事件如何写?
- c# winform 中listview的宽度能用比例显示吗????
- winform中的日历控件如何与TextBox结合使用,当我在TextBox获取焦点时弹出日历控件,要把在日历控件范围内的其他控件遮挡起来
- 关于在Winform下TreeView的使用问题
- 模板列中DorpDownList选择后刷新回到顶部的问题
- 在toolstripmenuitem菜单中怎样静态的能显示&字符串
- c#数组按什么方式传递,值还是引用?
- 一个简单问题,马上结贴
- 易生支付使用MD5签名算法,并且给出签名密钥(安全校验码)为abc123
- C#反射泛型赋值问题求支援求助攻
- comboBox赋值问题
- 代码封装小问题
Application.StartupPath + "\\" + file_name_2
StreamWriter wr = new StreamWriter(filename);
C:\Documents and Settings\当前用户名
这个路径下面,有没有你创建的文件。
public static bool WriteFile(byte[] FileContent,string FilePath)
{
FileStream fs = null;
bool boRetVal = true;
try
{
fs = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(FileContent, 0, FileContent.Length);
}
catch (Exception)
{
boRetVal = false;
}
finally
{
if (fs != null) { fs.Flush(); fs.Close(); fs.Dispose(); }
}
return boRetVal;
}
public static void CreateFile( String template, String path )
{
System.IO.StreamWriter objSW = null;
try
{
objSW = new System.IO.StreamWriter( path, false, System.Text.Encoding.UTF8 );
objSW.Write( template );
objSW.Flush();
objSW.Close();
CNCDotNet.Really_Simple_Syndication.Asynchronous.Init_App();
}
catch( Exception ex )
{
ErrorCaptor.Descendant("创建文件异常", ex.ToString());
}
finally
{
if( objSW != null )
{
objSW.Close();
objSW = null;
}
}
}