zoukankan      html  css  js  c++  java
  • 读取文件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 "";
            }

  • 相关阅读:
    Java应用程序的运行机制
    IO流——字符流
    IO流——字节流
    Java API --- File类
    SSM框架整合
    Mybatis核心组件
    AJAX 练习
    设计者模式
    软件七大设计原则
    并发编程
  • 原文地址:https://www.cnblogs.com/change4now/p/5665199.html
Copyright © 2011-2022 走看看