當前位置:首頁 » 編程軟體 » java如何生產執行bat腳本

java如何生產執行bat腳本

發布時間: 2025-09-18 16:53:25

① bat腳本如何調用java程序

bat文件內容如下:
cd <arg0>
java <-classpath arg1> <-jar> arg2 <arg3 arg4..>

說明:
<尖括弧里的不是必須的,按你的具體情況來>
arg0:你的class或jar文件所在目錄
arg1:你需要引入的jar文件,如果你已經在window的classpath里配置過或者不需要,那這句可以去掉
arg2:java類(*.class或*.jar)文件
arg3 arg4..:若干個參數,如沒有也可以去掉

前提是你安裝了jdk,並配置了環境變數

② java調用bat文件傳入參數,急,急,急!

java好像不能直接給bat文件傳參數,不過你可以先生成一個你需要的bat文件,再去執行這個bat文件,我就是這么做的,給你寫了個例子,你參考下(你先在d盤下建一個text.txt)
public class DelFile {
public void creatBat(String command){
FileWriter fw=null;
try {
fw=new FileWriter("D:\\del.bat");
fw.write(command);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(0);
}finally{
if(fw!=null){
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(0);
}
}
}
}

private String execute(String batname){
Process process;
String line = null;
StringBuffer sb=new StringBuffer();
try {
process = Runtime.getRuntime().exec(batname);
InputStream fis = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
if(process.waitFor()!=0){
System.out.println("fail");
return "fail";
}
System.out.println(batname+" run successful!");
return "success";
} catch (Exception e) {
e.printStackTrace();
return "fail";
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
DelFile df=new DelFile();
df.creatBat("del D:\\text.txt");
df.execute("D:\\del.bat");
}

}

③ Java中如何調用bat,並傳入參數

如果能動態指定bat文件中參數更好。例如: 1.bat中> java -cp Chart2D這里有調用windows程序的例子,你可以參考一下,就在調用的地方吧你的bat文件

熱點內容
戰地5默認是什麼伺服器 發布:2025-09-18 17:59:32 瀏覽:296
安卓變ios系統主題怎麼弄 發布:2025-09-18 17:54:07 瀏覽:875
linux出口ip 發布:2025-09-18 17:51:57 瀏覽:936
androidbitmap使用 發布:2025-09-18 17:49:20 瀏覽:230
數字日期加密 發布:2025-09-18 17:43:46 瀏覽:495
網吧電腦顯示未連接上桌面伺服器 發布:2025-09-18 17:37:17 瀏覽:693
電腦壓縮文件怎麼解壓 發布:2025-09-18 17:27:59 瀏覽:383
資料庫數據類型表 發布:2025-09-18 17:11:56 瀏覽:27
java如何生產執行bat腳本 發布:2025-09-18 16:53:25 瀏覽:557
湖北的伺服器地址是多少 發布:2025-09-18 16:51:09 瀏覽:490