我确实右键单击了我的项目,然后单击“添加”>“现有项目”,然后从硬盘上选择了文本文件。现在,我在解决方案资源管理器的右侧窗口中看到该文件。
现在我想做两件事。首先要确保别人是否会使用该项目,或者仅会运行该exe程序,或者在以后进行安装时,该程序将不仅可以使用该文本文件,还可以使用我的文本文件。我的意思是,如果计算机上的其他人将使用该程序,则不会抛出该文本文件丢失的异常。
第二,我如何从代码中的文件中读取?
private void ManageDirectories()
{
string savedImagesPath = Path.GetDirectoryName(Application.LocalUserAppDataPath);
string mainPath = "Test";
mainPath = Path.Combine(savedImagesPath, mainPath);
//string[] lines = File.ReadAllLines
}
我想使用File.ReadAllLines读取文本文件的行
如果您希望此文件与文件一起存在于Debug/Release
文件夹中,.exe
则应将Copy to Output Directory
option设置为true。
去做这个:
在Properties
设置Copy to Output Directory
为的窗口中单击文件-> true
。
要从某个文件读取所有行,可以使用File.ReadAllLines()
:
string[] lines = File.ReadAllLines("somefile.txt"); //change path and name of your file.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句