如何将数组数据写入文本文件? [英] How to write array data into text file?

查看:771
本文介绍了如何将数组数据写入文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我想让该程序创建一个文本文件来存储数据.
可以创建文本文件,但是当在PDA中显示时,数据变成正方形块.

我该如何解决这个问题,请指教.

Hi, all!

I want to let this programme create a text file to store data.
The text file can be created, but the data became square blocks when displayed in PDA.

How do I solve this problem, please advise.

Dim Info(5) As Byte
SerialPort1.Read(Info, 0, 5)

TextBox1.Text = Info(0)
TextBox2.Text = Info(1)
TextBox3.Text = Info(2)
TextBox4.Text = Info(3)

Dim FS As FileStream
FS = New FileStream("\My Documents\test.txt", FileMode.Append, FileAccess.Write)

FS.Write(Info, 0, Info.Length)
FS.Close()





Thx in advance!

推荐答案

使用Binary Writer代替Stream Writer ..,因为SerialPort也可以读取Binary Data.
这是使用字节数组写入二进制文件的代码

Use the Binary Writer Instead of Stream Writer.., Because SerialPort can read Binary Data Also..,

Here is the code for write Binary file using the byte array

byte[] temp = new byte[100];
  FileStream fs = new FileStream("c:\\temp.txt", FileMode.Create);
  BinaryWriter Bw = new BinaryWriter(fs);
  Bw.Write(temp);
  Bw.Close();
  fs.Close ();


致谢!
我尝试了BinaryWriter,但其结果与StreamWriter相同,但文本文件中的数字数组仍显示为块.
所以我改变了方向哈.我只是将所有文本框用作数据源",而不是字节.
现在可以正常工作了! :)
Thx for reply!
I tried BinaryWriter, but it has the same result as StreamWriter, number array into the textfile still showed as blocks.
So i changed my direction ha. I just use all the textboxes as my ''data source'' instead of Bytes.
Now it can work! :)


这篇关于如何将数组数据写入文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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