.net c#为什么我的 FileStream 路径被更改为包含我的代码路径?

Why is my FileStream path being changed to include the path of my code? [closed]
2021-12-04
  •  译文(汉语)
  •  原文(英语)

好的,所以我使用此代码:

FileStream FS;
StreamWriter SW;
FS = new FileStream(path: newFileName, mode: FileMode.Append);
SW = new StreamWriter(FS);
SW.WriteLine(message);
SW.Close();
SW.Dispose();
FS.Close();
FS.Dispose();

并且当运行文件时,代码的路径包含在 newFileName 中.为什么?这是vs中的设置吗?我错过了什么?它曾经工作过.

要明确发生这种情况的路线是:

FS = new FileStream(path: newFileName, mode: FileMode.Append);
解决过程1

newFileName是一个相对路径.在项目设置中检查您的工作目录.问题是代码是如何设置的newFileName.

OK so I use this code:

FileStream FS;
StreamWriter SW;
FS = new FileStream(path: newFileName, mode: FileMode.Append);
SW = new StreamWriter(FS);
SW.WriteLine(message);
SW.Close();
SW.Dispose();
FS.Close();
FS.Dispose();

And when run the file The path to the code is included with the newFileName. Why? is it a setting in vs? what am I missing? it used to work.

To be clear the line where this is happening is:

FS = new FileStream(path: newFileName, mode: FileMode.Append);
Solutions1

Your newFileName is a relative path. Check your working directory in the project settings. The issue is how the code is setting newFileName.

转载于:https://stackoverflow.com/questions/15208251/why-is-my-filestream-path-being-changed-to-include-the-path-of-my-code

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入