码迷,mamicode.com
首页 > 其他好文 > 详细

读取文件txt

时间:2016-07-12 23:22:42      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

        /// <summary>
        /// 读取文件
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static String ReadFile()
        {
            string path = AppDomain.CurrentDomain.BaseDirectory+"data.txt";
            Log(path);
            Log(File.Exists(path)?"存在":"不存在");
            if (File.Exists(path))
            {
   
                byte[] byData = new byte[1000];
                char[] charData = new char[10000];
                try
                {
                    StreamReader sr = new StreamReader(path, Encoding.Default);
                    String line;
                    var result = "";
                    while ((line = sr.ReadLine()) != null)
                    {
                        result+=line;
                    }
                    Log(result);
                    return result;
                }
                catch (IOException e)
                {
                    Log(e.Message);
                    return "";
                }
            }
            return "";
        }

读取文件txt

标签:

原文地址:http://www.cnblogs.com/change4now/p/5665199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!