读取文本文件时出现问题 [英] Problem with reading a text file

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

问题描述

hi
我想从文本文件中读取文本,并将其显示在文本框中.
我逐行读取了文件,但无法读取输入字符.
例如:
我的文本文件是:
这是一个测试.
这是一个测试.
和文本框显示:
这是一个测试.这是一个测试.

请帮助我

hi
I want to read from a text file and display its in a textbox .
I read the file line by line but it can not read enter character.
for example:
my text file is:
this is a test.
this is a test.
and textbox disply:
this is a test.this is a test.

please help me

推荐答案

我使用了以下代码,对我来说很好用:
I used the following code and it worked fine for me:
textBox1.Text= System.IO.File.ReadAllText(@"C:\test.txt");



我将文本框的Multiline属性设置为true并执行了代码.
我的文本框显示的格式内容与文件完全相同.

希望此帮助



I set the Multiline property of text box to true and executed the code.
My text box showed exactly the same formatted contents as in file.

Hope this help


在读取行之间添加Environment.NewLine.

Add an Environment.NewLine between the read lines.

textBox.Text + = Environment.NewLine + lineJustRead;



干杯



Cheers


这篇关于读取文本文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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