读取文件txt

        /// <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 "";
        }

posted @ 2016-07-12 22:43  change_4_now  阅读(170)  评论(0编辑  收藏  举报