
C#中在记事本中写入数据的问题
小弟的代码(小弟想在记事本中记录一些内容,实践证明该代码不能写入小弟想要输入的内容,求大虾帮助)usingSystem;usingSystem.Collections.G...
小弟的代码(小弟想在记事本中记录一些内容,实践证明该代码不能写入小弟想要输入的内容,求大虾帮助)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
private void button1_Click(object sender, EventArgs e)
{
Process p = new Process();
p.StartInfo.FileName = "notepad";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.Start();
p.StandardInput.Write("要输入的内容"); //在此输入内容
p.StandardInput.WriteLine("要输入的内容"); //在此输入内容
p.Close();
}
其实我想要的效果就是要在点这个button后可以看到输出的内容。最好能输出到控制台,因为有段程序需要控制台才能实现。 展开
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
private void button1_Click(object sender, EventArgs e)
{
Process p = new Process();
p.StartInfo.FileName = "notepad";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.Start();
p.StandardInput.Write("要输入的内容"); //在此输入内容
p.StandardInput.WriteLine("要输入的内容"); //在此输入内容
p.Close();
}
其实我想要的效果就是要在点这个button后可以看到输出的内容。最好能输出到控制台,因为有段程序需要控制台才能实现。 展开
2个回答
展开全部
private void button1_Click(object sender, EventArgs e)
{
System.IO.StreamWriter a = new StreamWriter(@"c:\1.txt",true,Encoding.Unicode);
a.Write(textBox1.Text);
a.Flush();
a.Close();
StreamReader b = new StreamReader(@"c:\1.txt", Encoding.Unicode);
textBox2.Text = b.ReadToEnd();
}
有2个BUG 你自己研究吧,~我只是给你个例子,,System.IO.Stream 百度下资料你自己看看就明白了
{
System.IO.StreamWriter a = new StreamWriter(@"c:\1.txt",true,Encoding.Unicode);
a.Write(textBox1.Text);
a.Flush();
a.Close();
StreamReader b = new StreamReader(@"c:\1.txt", Encoding.Unicode);
textBox2.Text = b.ReadToEnd();
}
有2个BUG 你自己研究吧,~我只是给你个例子,,System.IO.Stream 百度下资料你自己看看就明白了
追问
那输出到控制台中可以吗?又该怎样写代码?
追答
窗体跟控制台不一样的吧,窗体很多东西控制台实现不了.. 你到底想干什么呢,?QQ574023323 Q聊吧
点击按钮后,想看到这个消息就简单了,用messagebox.show(b.ReadToEnd());
弹出来,
至于到控制台 我不了解怎么搞...不过可以探讨.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询