Java教程

控制台简易程序启动器代码

本文主要是介绍控制台简易程序启动器代码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

using System;
using System.IO;//引入IO
using System.Text;
using System.Diagnostics;

namespace APPLauncher
{
    class Program
    {
        public static void Main(string[] args)
        {
            try
            {
                //读取ini文件
                byte[] b = new byte[1024 * 1024];
                FileStream fileRead = new FileStream("Options.ini", FileMode.OpenOrCreate, FileAccess.Read);
                int r = fileRead.Read(b, 0, b.Length);
                string contents = Encoding.Default.GetString(b, 0, r);
            
                //打开程序
                Process process = new Process();//声明一个进程类对象
                process.StartInfo.FileName =@contents;
                process.Start();
            }
            catch
            {
                Console.WriteLine("-----------路径出错,未能启动应用程序-----------\n\n请在创建的[Options.ini]文件中输入应用相对路径,例如:\n\n根目录:\n ..\\test.txt \n上级目录:\n..\\..\\test.txt\n");
                Console.Write("Press any key to continue . . . ");
                Console.ReadKey(true);
            }
        }
    }
}

这篇关于控制台简易程序启动器代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!