File类方法读写文件

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_File类方法读写文件
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string path = @"D:\\C#代码学习\\IO操作\\练习文件\\1.txt";
            //读数据
            //返回数组
            string[] counts=File.ReadAllLines(path);
            //foreach (string s in counts) 
            //{
            //Console.WriteLine(s);
            //}

            //返回字符
            //string str=File.ReadAllText(path,Encoding.UTF8);
            //Console.WriteLine(str);


            //绝对路径:通过给的路径可以直接在电脑中找到这个文件
            //相对路径:把文件放到于可执行的文件的路径下 Debug下
            //开发中尽量使用相对路径

            //写数据
            //会覆盖原数据

            //File.WriteAllLines(path,new string[] {"a","b","c","D" } );
            //Console.WriteLine("写入成功");

            //File.WriteAllText(path,"ASDCDBLACLJA");
            //Console.WriteLine("写入成功");

            //追不覆盖原数据,追加
            File.AppendAllText(path,"我看有没有把你覆盖掉");
            Console.WriteLine("写入成功");
            Console.ReadKey();
        }
    }
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值