farmer joe 怎么翻译:C#逐行读取和写入TXT文件
来源:百度文库 编辑:中财网 时间:2024/04/29 08:26:12
using System;using System.IO;
class Test{ static void Main(string[] args) { readTxtFile(); writeTxtFile(); } public static void readTxtFile() { try { // Create an instance of StreamReader to read from a file. // The using statement also closes the StreamReader. //StreamReader sr = new StreamReader(@"D:\a.txt"); using (StreamReader sr = new StreamReader("TestFile.txt")) { String line; // Read and display lines from the file until the end of // the file is reached. while ((line = sr.ReadLine()) != null) { Console.WriteLine(line); } } } catch (Exception e) { // Let the user know what went wrong. Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } }
public static void writeTxtFile()//(string[] args) { string[] strs = new string[] { "10.100.182.89", "10.100.182.90" }; using (FileStream fileStream = File.OpenWrite("D:\\test.txt")) { using (StreamWriter writer = new StreamWriter(fileStream)) { foreach (string s in strs) { writer.WriteLine(s); } writer.Close(); } } }
}
class Test{ static void Main(string[] args) { readTxtFile(); writeTxtFile(); } public static void readTxtFile() { try { // Create an instance of StreamReader to read from a file. // The using statement also closes the StreamReader. //StreamReader sr = new StreamReader(@"D:\a.txt"); using (StreamReader sr = new StreamReader("TestFile.txt")) { String line; // Read and display lines from the file until the end of // the file is reached. while ((line = sr.ReadLine()) != null) { Console.WriteLine(line); } } } catch (Exception e) { // Let the user know what went wrong. Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } }
public static void writeTxtFile()//(string[] args) { string[] strs = new string[] { "10.100.182.89", "10.100.182.90" }; using (FileStream fileStream = File.OpenWrite("D:\\test.txt")) { using (StreamWriter writer = new StreamWriter(fileStream)) { foreach (string s in strs) { writer.WriteLine(s); } writer.Close(); } } }
}
如何读取和写入Excel和Word文件
C# 怎么文件写入啊?
怎样在ASP中,用txt文本文件储存数据库,并实现读取和写入等操作??
C#下,创建txt和html,并由html读取txt的内容来显示(怎样实现?)
用C读取TXT文件
VB读取写入[非TXT]-->大小虾通吃
asp 逐行读取 数据库内容
把$a变量写入文件file.txt
vb写入txt文件多行
C#中如何实现将文本和图形同时写入一个文件
PHP文件读取和写入问题~~答得好有加分的哦!~~~
VB6.0如何读取和写入xml文件,最好给出源代码!
c#程序怎么读取xml文件?
c# 怎么读取一个文件(替换)
vb读取txt文件的内容
VB读取TXT文件的一个问题
有关vc 读取txt文件的问题
如何逐行读取 TextArea 文本框中的文字?
帮帮忙啊!!!C# 的字符串写入文件 怎么实现????
关于asp远程读取文件写入到本地
请问VB中如何读取txt文件的数据
有关C语言 读取txt文件的问题
如何编写在VB中读取TXT文件的语句?
在VB 怎么读取大的TXT文件?