Read / Write Textfiles

Reading a simple Textfile

The File access classes are in the System.IO namespace, that needs to be included.
It's really easy, so I only give a C# and basic sample. It just prints a textfile with line numbers.

C# sample

// ReadTextFile.cs
// (C) Copyright 2003 by Johannes Roith

using System;
using System.IO;

class ReadTextFile {

	static void Main()
	{
   		StreamReader file1;
		int i = 1;

		file = File.OpenText("readme.txt");


		while (file.Peek() != null)
		{
			Console.WriteLine(i + " " + file.ReadLine());
			i++;
		}

	}
}

MonoBasic sample

// ReadTextFile.vb
// (C) Copyright 2003 by Johannes Roith

imports System
imports System.IO

Public Module ReadTextFile {

	Public Sub Main ()

   		StreamReader file1
		int i = 1

		file = File.OpenText("readme.txt")

		While (file.Peek() != null)

			Console.WriteLine(i + " " + file.ReadLine())
			i++

		End While

	End Sub

 End Module

Writing a Textfile

A more interesting Example. Gets Xml from the server, reads it and puts out a Textfile.