我有以下代码......
码:
private void button2_Click(object sender, EventArgs e)
{
strPath = @"C:\QRXS";
string strFile = @"C:\QRXS\download.lst";
if (Directory.Exists(strPath))
{
try
{
if (File.Exists(strFile))
{
try
{
ln = File.ReadAllLines(strPath);
}
catch (Exception ex)
{
// inform user or log depending on your usage scenario
MessageBox.Show(ex.Message, "FILE ACCESS");
}
if (ln != null)
{
MessageBox.Show(ln.Length + "");
// do something with lines
}
}
}
catch (Exception ce)
{
MessageBox.Show(ce.Message, "FOLDER ACCESS");
}
}
}
Run Code Online (Sandbox Code Playgroud)
每次运行应用程序(也使用Run as Administrator)时,都会继续调用以下行:
MessageBox.Show(ex.Message, "FILE ACCESS");
我该如何解决?
更换:
File.ReadAllLines(strPath);
Run Code Online (Sandbox Code Playgroud)
有:
File.ReadAllLines(strFile);
Run Code Online (Sandbox Code Playgroud)
原因:strPath表示目录.您试图将其内容读取为文件,但这显然不起作用.
| 归档时间: |
|
| 查看次数: |
110 次 |
| 最近记录: |