111,126
社区成员
发帖
与我相关
我的任务
分享
class Program
{
static void Main(string[] args)
{
StreamReader file = new StreamReader("d:\\a.txt",Encoding.Default);
int a = 0;
try
{
a= file.Read();
while (a!=-1)
{
Console.WriteLine(Convert.ToString(a,16));
Console.WriteLine((char)a);
a = file.Read();
}
}
catch (Exception e) { Console.WriteLine(e.Message); }
}
}
using System;
using System.IO;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
try
{
if (File.Exists(path))
{
File.Delete(path);
}
using (StreamWriter sw = new StreamWriter(path))
{
sw.WriteLine("This");
sw.WriteLine("is some text");
sw.WriteLine("to test");
sw.WriteLine("Reading");
}
using (StreamReader sr = new StreamReader(path))
{
while (sr.Peek() >= 0)
{
Console.Write((char)sr.Read());
}
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}