C# 使用FileStream读取文件
嗨,我在用C# 使用FileStream读取文件,c#,filestream,C#,Filestream,嗨,我在用 FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read); 从调试目录中定义的临时文件夹中读取文件,但没有成功。 有了这段代码,我可以从调试文件夹中读取文件。 有人能帮忙吗 这是我的密码 private void button_click(object sender, RoutedEventArgs e) { string activeDirectory = Sy
FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read);
从调试目录中定义的临时文件夹中读取文件,但没有成功。
有了这段代码,我可以从调试文件夹中读取文件。
有人能帮忙吗
这是我的密码
private void button_click(object sender, RoutedEventArgs e)
{
string activeDirectory = System.Windows.Forms.Application.StartupPath + "\\Temp\\";
string[] files = Directory.GetFiles(activeDirectory);
try
{
foreach (string fileName in files.Select(f => f.Substring(activeDirectory.Length)))
{
FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read);
}
}
catch()
{}
}
如果您正在运行调试生成,则
System.Windows.Forms.Application.StartupPath
将返回调试文件夹的路径,因为您的exe存在于该文件夹中。发生了什么问题/您遇到了什么问题?为了能够帮助您,我们需要了解您如何获取fileName变量。不要接受异常。它们可能包含有关该问题的有用信息。我希望能够访问临时文件夹。我只希望有文件名示例filename.txt,这意味着“跳过x个字符并返回其余字符”