本文介绍了如何在安装.exe控制台应用程序时创建文本文件并在该应用程序中读取创建的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string [] flines = File.ReadAllLines(filenamelocation);
string path = string.Concat(Environment.CurrentDirectory,@\ commport.txt);
和
string[] flines = File.ReadAllLines(filenamelocation);
string path = string.Concat(Environment.CurrentDirectory, @"\commport.txt");
and
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
string filenamelocation = System.IO.Path.Combine(path, "commport.txt");
我们尝试过上面的代码,但我们无法得到结果
专家请帮助解决上述问题
we have tried the above code but we couldnot get the result
Experts please help the above problem
推荐答案
//write
string path = @"D:\YourPath\Test.txt";
if (!File.Exists(path))
{
File.Create(path);
TextWriter tw = new StreamWriter(path);
tw.WriteLine("test line 1!");
tw.Close();
}
else if (File.Exists(path))
{
TextWriter tw = new StreamWriter(path, true);
tw.WriteLine("test line 2!");
tw.Close();
}
//read
string texts = ReadAllText(@"D:\YourPath\Test.txt");
System.Console.WriteLine("File Test.txt contains = {0}", texts);
如果这不能解决您的问题,请回复。
In case, this doesn't solve your problem, please reply.
这篇关于如何在安装.exe控制台应用程序时创建文本文件并在该应用程序中读取创建的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!