创建文本文件. [英] Creating text file.

查看:119
本文介绍了创建文本文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我迫切需要你们的帮助.我想在我的C盘中创建文本文件.我搜索代码并实现但未成功插入值.我要在其之前插入的值将从我的列表框中删除.每隔2秒以及在其中包含6个数据之后,文本文件都需要刷新.这是我的代码:

如果(listBox1.Items.Count> = 7)
{
字符串路径= @"C:\ data.txt";
StreamWriter sw =新的StreamWriter(path);

Thread.Sleep(200);
for(int i = 0; i< listBox1.Items.Count; i ++)
{
sw.WriteLine(m_strTagUID);
listBox1.Items.RemoveAt(0);
}
sw.Close();
sw.Dispose();

}

I need urgently help from you guys. i wanted to create textfile in my c drive. ive search for the code and implemented but unsuccessful inserting the value. The value that i want to insert before its will be removes from my listbox.and every 2 second and after containing 6 data in it, the textfile need to be refresh. here my code:

if (listBox1.Items.Count >= 7)
{
string path = @"C:\data.txt";
StreamWriter sw = new StreamWriter(path);

Thread.Sleep(200);
for (int i = 0; i < listBox1.Items.Count; i++)
{
sw.WriteLine(m_strTagUID);
listBox1.Items.RemoveAt(0);
}
sw.Close();
sw.Dispose();

}

推荐答案

我发现您的问题不清楚,但是如果您想每2秒执行一次操作,则需要使用计时器,那么您编写的代码只会停止执行该代码持续2秒钟.
对于更具可读性的代码,请使用此
I found your question not clear but if you want to execute something every 2 seconds you need to use a timer , the code you wrote just stop executing the code for 2 seconds.
and for more readable code use this
using (StreamWriter sw = new StreamWriter(path))
{
}
//here the the stream will close and dispose automatically 



希望我能帮上忙



hope that i could help


这篇关于创建文本文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆