主题:[投票]帮帮忙,一个FILE问题
//带命令行参数的文件拷贝
//程序清单17-3:
using System;
using System.IO;
class FileTest
{
public static void Main(String[] args)
{
//验证参数输入是否正确
string sourcename;
string targetname;
try{
sourcename = args[0];
}
catch
{
Console.WriteLine("Please input the name of the source file correctly");
return;
}
try{
targetname = args[1];
}
catch
{
Console.WriteLine("Please input the name of the target file correctly");
return;
}
//进行文件拷贝操作
File file;
try{
file = new File(sourcename);
}
catch
{
Console.WriteLine("Can not open the source file named '{0}'",sourcename);
return;
}
try{
file.CopyTo(targetname,true);
}
catch
{
Console.WriteLine("Can write the target file named '{0}'",targetname);
return;
}
Console.WriteLine("File copys successfully!");
}
}
运行的时候说是file = new File(sourcename);不能重载获得“1”,还有就是找不到“CopyTo”,第一个可能是因为没有给“sourcename”负直,但是第2个我就不清楚了,怎么改都不对,请各位高手帮帮忙!!!
谢谢!!!
[em10]
//程序清单17-3:
using System;
using System.IO;
class FileTest
{
public static void Main(String[] args)
{
//验证参数输入是否正确
string sourcename;
string targetname;
try{
sourcename = args[0];
}
catch
{
Console.WriteLine("Please input the name of the source file correctly");
return;
}
try{
targetname = args[1];
}
catch
{
Console.WriteLine("Please input the name of the target file correctly");
return;
}
//进行文件拷贝操作
File file;
try{
file = new File(sourcename);
}
catch
{
Console.WriteLine("Can not open the source file named '{0}'",sourcename);
return;
}
try{
file.CopyTo(targetname,true);
}
catch
{
Console.WriteLine("Can write the target file named '{0}'",targetname);
return;
}
Console.WriteLine("File copys successfully!");
}
}
运行的时候说是file = new File(sourcename);不能重载获得“1”,还有就是找不到“CopyTo”,第一个可能是因为没有给“sourcename”负直,但是第2个我就不清楚了,怎么改都不对,请各位高手帮帮忙!!!
谢谢!!!
[em10]