异常:用自己编写的记事本打开系统文件无法进行读取
想用自己编写的记事本打开系统文件,开始的获取系统文件路径都没问题,可是到读取的过程中出现了异常,求教:
程序代码:static void Main()
{
string[] getArgs = Environment.GetCommandLineArgs();//获取命令行参数,经测试,打开系统文件时的文件路径在第二行
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmNote(getArgs));
}
程序代码: public FrmNote(string[] getSystemFilePath)
{
if (getSystemFilePath.Length > 1)//调试时命令行参数只有1行,只有当打开系统文件时命令行参数才大于1行
{
MessageBox.Show(getSystemFilePath[1]);
FileStream fs = new FileStream(getSystemFilePath[1], FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
MessageBox.Show("a");
StreamReader sr = new StreamReader(fs);
MessageBox.Show("b");
tbContent.Text = sr.ReadToEnd();
MessageBox.Show("c");
sr.Close();
fs.Close();
}
InitializeComponent();
//ff = new FrmFind();
//ff.Show(this);
//ff.Hide();
}public System.Windows.Forms.TextBox tbContent;
尝试打开系统文件时出现异常:
发现问题出现在
tbContent.Text = sr.ReadToEnd();
却不知道怎么解决,毫无头绪









