import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
InputStream PROGRAM = Main.class.getClassLoader().getResourceAsStream("FILES/PROGRAM.bat");
converter(PROGRAM);
String s = "" + PROGRAM;
System.out.println(s);
Runtime.getRuntime().exec("cmd.exe /c start "+s);
}
static String converter(InputStream a)throws Exception{
InputStream in = a;
InputStreamReader is = new InputStreamReader(in);
StringBuilder sb=new StringBuilder();
BufferedReader br = new BufferedReader(is);
String read = br.readLine();
while(read != null) {
sb.append(read);
read =br.readLine();
}
return sb.toString();
}
}
我想要做的是将这个项目导出到 Jar 文件中,我需要像这样导入这个批处理文件: InputStream PROGRAM = Main.class.getClassLoader().getResourceAsStream("FILES/PROGRAM.bat"); 所以它可以在任何其他计算机上工作。