前言
- 这个程序的诞生完全是因为我每天开机都要打开相同的程序,不断重复同样的操作,看到有按键精灵之类的脚本软件,自己就想我能不能自己实现一个呢.
- 代码很简单,完全不支持扩展性,因为每次打开的程序都是固定的,所以没必要去在写一个添加自定义快速启动项
我可不会告诉你们是因为技术原因,没办法解决
- 自己还是一只Java初学者的小白,所以分享给像我一样的小白
源代码
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class QuickProgramLanucherMain {
public static void main(String args[]){
System.out.println("+----------------------------------------------------------+");
System.out.println("| |");
System.out.println("| ===== ======= ======= |");
System.out.println("| | | | \\ \\/ \\/ |");
System.out.println("| ===== | |_______/ | |");
System.out.println("| | | | | | |");
System.out.println("| ===== | | \\ \\ | / |");
System.out.println("| | | \\__ \\_____/ |");
System.out.println("| |");
System.out.println("| |");
System.out.println("| 作者:StringOD 欢迎使用快速程序启动器(QuickProgramLanucher). |");
System.out.println("| GitHub:https://github.com/TianruiShi/str |");
System.out.println("| By StringOD welcome to QuickProgramLanucher. |");
System.out.println("+----------------------------------------------------------+");
System.out.println("1. 显示默认已添加路径 2. 启动默认程序 3.退出程序");
File file = new File("info.txt");
Scanner scanner = new Scanner(System.in);
while(true){
int input = scanner.nextInt();
switch (input){
case 1:
try{
FileReader fileReader = new FileReader(file);
int read = 0;
try{
char ch[] = new char[100];
while ((read = fileReader.read(ch,0,100)) != -1){
}
for(int i=0;i<ch.length;i++)
System.out.print(ch[i]);
}
catch (IOException e1){
System.out.println("不能读取或打开info.txt配置文件,请查看是否被其他程序占用");
}
}
catch (FileNotFoundException e){
System.out.println("找不到配置文件,请在程序运行目录下创建info.txt文本文档");
}
break;
case 2:
Runtime runtime = Runtime.getRuntime();
try{
runtime.exec("D:\\网易云音乐\\CloudMusic\\cloudmusic.exe");
runtime.exec("D:\\腾讯QQ\\Bin\\QQ.exe");
runtime.exec("D:\\HBuilder\\HBuilderX\\HBuilderX.exe");
FileWriter fileWriter = new FileWriter(file);
fileWriter.write("D:\\网易云音乐\\CloudMusic\\cloudmusic.exe");
fileWriter.write("D:\\腾讯QQ\\Bin\\QQ.exe");
fileWriter.write("D:\\HBuilder\\HBuilderX\\HBuilderX.exe");
fileWriter.flush();
}
catch (IOException e){
System.out.println("程序不能被打开,因为不是合法的EXE可执行二进制程序");
}
break;
case 3:
return;
default:
System.out.println("不合法的操作");
}
}
}
}