存储数据的文本文件
我想将一些数据保存到我的 C# 应用程序中的文本文件中。我将文本文件添加到项目的根目录中。
我现在如何访问它?这个文件会嵌入到我的exe中还是什么?
I want to persist some data into a text file in my C# application. I added the text file to the root of my project.
How do I access it now? Will this file be embedded with my exe or what?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
听起来您的文本文件将包含应用程序的“设置”,如果您想嵌入这些设置,则只需使用项目中内置的实际设置即可。属性>设置。 MSDN:设置
It sounds like your text file will contain "settings" for your application, and if you want to embed these settings then just use the actual Settings built into the project. Properties>Settings. MSDN: Settings
还有优秀的 Nini 项目 (http://nini.sourceforge.net/manual.php )这使得访问(和编写)各种风格的简单设置文件变得容易,并可以选择将它们与命令行参数组合。
There's also the excellent Nini project (http://nini.sourceforge.net/manual.php) which makes it easy to access (and write) simple settings files of various flavors and to optionally combine them with command line parameters.
首先,确保右键单击该文件并选择“复制到输出目录”。
其次,该文件不会嵌入到您的可执行文件中。它将是一个普通的 *.txt 文件,与您的 *.exe 一起,您可以这样访问它:
First, make sure that you right click the file and select "Copy to Output Directory".
Second, the file will not be embedded inside of your Executable. It will be a normal *.txt file alongside your *.exe and you would access it as such:
它不会嵌入您的exe中。
阅读本文以获取有关打开文件的帮助。
It will not be embedded with your exe.
Read this for help on opening a file.
默认情况下,它将与您的 exe 位于同一目录中,您还可以提供一个特定的路径,可以通过您正在使用的 StreamWriter 或 w/e 类的构造将其放置到该路径。
It will be in the same directory as your exe by default, you can also provide a specific path where it can be dropped to via the construct of your StreamWriter or w/e class you are using.