File.ReadAllLines(“path”, Encoding.Default);//读取所有行,返回string[]
File.ReadAllText(“path”, Encoding.Default);//读取所有文本返回string
File.ReadAllBytes(“path”);//读取文件,返回byte[],把文件作为二进制来处理。===========================================
File.WriteAllLines(“path”, new string[4] ,Encoding.Default);//将string数组按行写入文件。
File.WriteAllText(“path”, “string”);//将字符串全部写入文件
File.WriteAllBytes(“path”,new byte[5]);//将byte[]全部写入到文件
File.AppendAllText()//将string追加到文件File.Copy(“source”, “targetFileName”, true);//文件拷贝,true表示当文件存在时“覆盖”,如果不加true,则文件存在报异常。
File.Exists();//判断文件是否存在
File.Move(“source”, “target”);//移动(剪切),思考如何为文件重命名?文件的剪切是可以跨磁盘的。
File.Delete(“path”);//删除。如果文件不存在,不报错
File.Create(“path”);//创建文件最后
以上就是可爱香菇最近收集整理的关于File类的用法的全部内容,更多相关File类内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复