using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace tasksgeneration
{
class Class1
{
static void Main(string[] args)
{
System.Console.WriteLine("\n控制台应用程序运行之后的内容怎么保存到记事本里边:");
File.CreateText("C:\\Users\\admin\\Desktop\\instance.txt");
// 接下来怎么写,上面是举例,要求将程序运行之后的内容保存到创建的text里
}
}
}
看类似的方法如下
File.WriteAllText(@"C:\a.txt",str,System.Text.Encoding.UTF8);
但是会提示“string”上下文中不存在。小白一枚,求教。
或者
FileStream fs = new FileStream("D:\\A.txt",FileMode.Apend);~~
会提示“Apend”不在“System.IO;”?
当然我的显示程序不止“hallow”“welcome”那么简单,就是把所有的窗体显示内容保存到text文件中
是第二种情况,但是有没有一步到位的。比如运行.exe或者启动调试就一步生成的
另外,参考别人的方法如下:
运行用系统的重定向就可以了.
xxx.exe>output.txt
这里的重定向什么意思,如何实现
你可以在另外一个项目里面运行cmd /c 路径>D:\a.txt来实现。其实就是把输出内容写到文件里去