/*
* Created by SharpDevelop.
* User: Administrator
* Date: 2006-1-30
* Time: 16:34
* Using C#
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.IO;
namespace list
{
class MainClass
{
public static void Main(string[] args)
{
try
{
int ctr=1;
if(args.Length<=0)
{
Console.WriteLine("命令格式:list filename");
}
else
{
FileStream f=new FileStream(args[0],FileMode.Open);
try
{
StreamReader r=new StreamReader(f);
string line;
while((line=r.ReadLine())!=null)
{
Console.WriteLine("{0}:{1}",ctr,line);
ctr++;
}
f.Close();
}
finally
{
f.Close();
}
}
}
catch(System.IO.FileNotFoundException)
{
Console.WriteLine("找不到指定的文件{0}",args[0]);
}
catch(Exception e)
{
Console.WriteLine("出错:/n{0}",e.Message);
}
}
}
}
* Created by SharpDevelop.
* User: Administrator
* Date: 2006-1-30
* Time: 16:34
* Using C#
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.IO;
namespace list
{
class MainClass
{
public static void Main(string[] args)
{
try
{
int ctr=1;
if(args.Length<=0)
{
Console.WriteLine("命令格式:list filename");
}
else
{
FileStream f=new FileStream(args[0],FileMode.Open);
try
{
StreamReader r=new StreamReader(f);
string line;
while((line=r.ReadLine())!=null)
{
Console.WriteLine("{0}:{1}",ctr,line);
ctr++;
}
f.Close();
}
finally
{
f.Close();
}
}
}
catch(System.IO.FileNotFoundException)
{
Console.WriteLine("找不到指定的文件{0}",args[0]);
}
catch(Exception e)
{
Console.WriteLine("出错:/n{0}",e.Message);
}
}
}
}
本程序使用C#实现了一个简单的控制台应用程序,该程序可以读取指定文件的内容并将其逐行显示在控制台上。程序首先检查命令行参数是否提供了一个文件名,然后尝试打开并读取文件。

6235

被折叠的 条评论
为什么被折叠?



