• 获取当前应用程序所在目录的路径


    c# winform用

    A:“Application.StartupPath”:获取当前应用程序所在目录的路径,最后不包含“”;
    B:“Application.ExecutablePath ”:获取当前应用程序文件的路径,包含文件的名称;
    C:“AppDomain.CurrentDomain.BaseDirectory”:获取当前应用程序所在目录的路径,最后包含“”;
    D:“System.Threading.Thread.GetDomain().BaseDirectory”:获取当前应用程序所在目录的路径,最后包含“”;
    E:“Environment.CurrentDirectory”:获取当前应用程序的路径,最后不包含“”;
    F:“System.IO.Directory.GetCurrentDirectory”:获取当前应用程序的路径,最后不包含“”;
     
            //恢复上次位置
            void LoadCount()
            {
                StreamReader slog = new StreamReader(LogFilePath, Encoding.Default);//
                string countLog = slog.ReadLine();
                if ("" != countLog && null != countLog)
                    count = int.Parse(countLog) - 1;//下标从0开始计算的
          
                slog.Close();
            }
    恢复上次位置
    //读取最高分数
    void LoadScoreMax()
    {         
        string fname = @"" + AppDomain.CurrentDomain.BaseDirectory + "ScoreFile";            
        string FilePath = Path.Combine(fname, "score.log");
    
        if (!File.Exists(FilePath))
            WriteFile();
    
        StreamReader slog = new StreamReader(FilePath, Encoding.Default);//
        string scoreLog = slog.ReadLine();
        if ("" != scoreLog && null != scoreLog)
        {
            ScoreMax = int.Parse(scoreLog);     
        }            
        slog.Close();       
    }
    LoadScoreMax()
    //保存记录
    void WriteFile()
    {
        string fname = @"" + AppDomain.CurrentDomain.BaseDirectory + "ScoreFile";
        if (!Directory.Exists(fname))//如果路径不存在
        {
            Directory.CreateDirectory(fname);//创建一个路径的文件夹
        }
    
        StreamWriter writer = new StreamWriter(Path.Combine(fname,"score.log"), false, System.Text.Encoding.Default);
        writer.WriteLine(ScoreMax.ToString());
    
        writer.Close();
    }
    WriteFile()
  • 相关阅读:
    登入界面的创建
    什么是IO流 以及文件输入输出
    java 的面向对象
    Mac 终端命令大全
    jQuery 的属性
    商城管理系统
    Java IO学习第二天部分详解
    Java IO学习第一天部分详解
    用JAVA描述一个车与修车厂两个事物
    JAVA基础(数组)数组排序和查找数组中是否还有某一个数
  • 原文地址:https://www.cnblogs.com/GoldenEllipsis/p/10662913.html
Copyright © 2020-2023  润新知