一个是静态类(File)一个是只能被实例化才能使用的(FileInf)          

  const string sourcepath = @"li.txt";
            const string destpath = @"lichen1.txt";
            //使用fileinfo构造函数的实例,需要传递一个文件的路径的字符串
            fileinfo ff = new fileinfo(sourcepath);
            //exists 方法在fileinfo也有
            if (!ff.exists)
            {
                using (streamwriter sw = ff.createtext())
                {
                    sw.writeline("李晨。txt ");
                    sw.flush();
                }
            }
            // ff.delete();
            file.delete(destpath);
            ff.copyto(destpath);
            file.delete(destpath);
            ff.moveto(destpath);
            //z追加文件
            using (streamwriter sw1 = ff.appendtext())
            {
                sw1.writeline("zuij");
                sw1.flush();

            }
            using (streamreader sr = ff.opentext())
            {
                console.writeline(sr.readtoend());
            }

Posted on 2011-01-06 10:13  lichen396116416  阅读(784)  评论(0编辑  收藏  举报