日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

java 生成bat_java实现生成windows可执行的批处理文件(.bat)

發布時間:2025/3/8 windows 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 生成bat_java实现生成windows可执行的批处理文件(.bat) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

/*** 下載壓縮包

*

*@paramid 商戶id

*@paramrequest

*@paramresponse

*@returnvoid

*@authorchen.bing

* @Date 2019/11/4 17:35*/@RequestMapping(value= "downloadzip")public voiddownloadzip(String id, HttpServletRequest request, HttpServletResponse response) {if(StringUtils.isBlank(id)) {

LOG.error("商戶id為空");return;

}

String rootZipUrl= Global.getProperty("VOUCHER_IMAGE_DIR");

File rootFile= newFile(rootZipUrl);if (!rootFile.exists()) {

LOG.error("當前文件夾不存在", rootZipUrl);return;

}

String zipUrl=rootZipUrl;

SysMerch sysMerch=sysMerchService.selectById(id);if (sysMerch != null) {

String scheme=request.getScheme();

String contextPath=request.getContextPath();

String serverName=request.getServerName();int port =request.getServerPort();

String basePath= scheme + "://" + serverName + ":" + port +contextPath;

String orgCode=sysMerch.getOrgCode();

String merchNo=sysMerch.getMerchNo();

String merchName=sysMerch.getMerchName();

String merchNameDir= rootZipUrl + File.separator +merchName;

String oldZipUrl= rootZipUrl + File.separator + "downloadZip";boolean b =FileUtils.fileNameRenameTo(oldZipUrl,merchNameDir);

zipUrl=oldZipUrl;if(b) {

zipUrl=merchNameDir;

}

String batUrl= zipUrl + File.separator + "安裝包" + File.separator + "setup.txt";

File file= newFile(batUrl);if (!file.exists()) {

File parentFile=file.getParentFile();if (!parentFile.exists()) {

parentFile.mkdirs();

}//不存在創建文件和其父目錄

FileUtils.createFile(batUrl);

}

setUpMerchLogo(orgCode, merchNo, merchName, request);

String merchLogoBat= "set wind = ws.createshortcut(strDesktop & \"\\%s.lnk\")";

String url= "wind.Arguments=\"%s\"";

String loginUrl= basePath + "/login?org_code_ck_key=" + orgCode + "&merch_no_ck_key=" +merchNo;

String logoBat=String.format(merchLogoBat, merchName);

String merchUrl=String.format(url, loginUrl);

List list = new LinkedList<>();

list.add("@echo off");

list.add("more %0 +5>%temp%yst.vbs");

list.add("%temp%yst.vbs");

list.add("del %temp%yst.vbs");

list.add("exit");

list.add("set ws = createobject(\"wscript.shell\")");

list.add("strDesktop = ws.SpecialFolders(\"Desktop\")");

list.add(logoBat);

list.add("wind.IconLocation = ws.CurrentDirectory & \"\\favicon.ico\"");

list.add("wind.targetpath = \"%ProgramFiles%\\Internet Explorer\\IEXPLORE.EXE\"");

list.add("wind.workingdirectory = \"%ProgramFiles%\\Internet Explorer\"");

list.add(merchUrl);

list.add("wind.save");

OutputStream outputStream= null;try{//加鎖,防止在壓縮時有圖片寫入

synchronized(ZIP_LOCK) {

outputStream= newFileOutputStream(file);//此處循環操作是因為要將.bat文件轉換為windows格式

for (int i = 0; i < list.size(); i++) {byte[] bytes = list.get(i).getBytes(Charset.forName("GB2312"));

outputStream.write(bytes);if (i

outputStream.write("\r\n".getBytes(Charset.forName("GB2312")));

}

}

outputStream.close();

String batPath= zipUrl + File.separator + "安裝包" + File.separator + "setup.bat";

File batFile= newFile(batPath);

batFile.delete();

FileUtils.fileNameRenameTo(batUrl,batPath);

FileUtils.downloadZip(response, rootZipUrl, merchName);

FileUtils.fileNameRenameTo(merchNameDir, oldZipUrl);file.delete();

}

}catch(FileNotFoundException e) {

e.printStackTrace();

}catch(IOException e) {

e.printStackTrace();

}

}

}

總結

以上是生活随笔為你收集整理的java 生成bat_java实现生成windows可执行的批处理文件(.bat)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。