V
viepia
Hi,
using System;
using System.IO;
namespace testBaseStream
{
class Program
{
static void Main(string[] args)
{
string fn = "temp.txt";
StreamWriter sw = new StreamWriter(fn);
sw.WriteLine("123456");
sw.Close();
StreamReader sr = new StreamReader(fn);
sr.BaseStream.Seek(3,SeekOrigin.Begin);
char[] c = new char[1];
sr.Read(c, 0, 1);
Console.WriteLine(String.Format("Seek 3: {0} Should be: 4",c[0]));
sr.BaseStream.Seek(2, SeekOrigin.Begin);
sr.Read(c, 0, 1);
Console.WriteLine(String.Format("Seek 2: {0} Should be: 3", c[0]));
sr.BaseStream.Seek(1, SeekOrigin.Begin);
sr.Read(c, 0, 1);
Console.WriteLine(String.Format("Seek 1: {0} Should be: 2", c[0]));
Console.ReadLine();
}
}
}
results:
Seek 3: 4 Should be: 4
Seek 2: 5 Should be: 3
Seek 1: 6 Should be: 2
StreamReader.BaseStream.Seek worked the first time it was called, but not the 2nd or 3rd.
BinaryReader.BaseStream.Seek and BinaryWriter.BaseStream.Seek both work.
Viepia
using System;
using System.IO;
namespace testBaseStream
{
class Program
{
static void Main(string[] args)
{
string fn = "temp.txt";
StreamWriter sw = new StreamWriter(fn);
sw.WriteLine("123456");
sw.Close();
StreamReader sr = new StreamReader(fn);
sr.BaseStream.Seek(3,SeekOrigin.Begin);
char[] c = new char[1];
sr.Read(c, 0, 1);
Console.WriteLine(String.Format("Seek 3: {0} Should be: 4",c[0]));
sr.BaseStream.Seek(2, SeekOrigin.Begin);
sr.Read(c, 0, 1);
Console.WriteLine(String.Format("Seek 2: {0} Should be: 3", c[0]));
sr.BaseStream.Seek(1, SeekOrigin.Begin);
sr.Read(c, 0, 1);
Console.WriteLine(String.Format("Seek 1: {0} Should be: 2", c[0]));
Console.ReadLine();
}
}
}
results:
Seek 3: 4 Should be: 4
Seek 2: 5 Should be: 3
Seek 1: 6 Should be: 2
StreamReader.BaseStream.Seek worked the first time it was called, but not the 2nd or 3rd.
BinaryReader.BaseStream.Seek and BinaryWriter.BaseStream.Seek both work.
Viepia