本文介绍了如何阅读项目的根目录下的文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想读我添加到我的项目的根目录下的文本文件的第一行。 。意思是,我的解决方案资源管理器是沿侧我的.cs文件在我的项目中的.txt文件
I want to read the first line of a text file that I added to the root directory of my project. Meaning, my solution explorer is showing the .txt file along side my .cs files in my project.
所以,我试图做的:
TextReader tr = new StreamReader(@"myfile.txt");
string myText = tr.ReadLine();
但因为它是指bin文件夹,这并不工作,我的文件是不是在那里......我怎样才能使这项工作? :/
But this doesn't work since it's referring to the Bin Folder and my file isn't in there... How can I make this work? :/
感谢
推荐答案
从解决方案资源管理器中,右键单击myfile.txt的,然后选择属性
From Solution Explorer, right click on myfile.txt and choose "Properties"
从那里,将生成操作
到内容
和复制到输出目录
为复制总是
或复制如果新
这篇关于如何阅读项目的根目录下的文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!