String t = Thread.currentThread().getContextClassLoader().getResource("").getPath();获取发布运行路径
//解决路径中空格的问题
t=URLDecoder.decode(t,"utf-8");
int num = t.indexOf("test");查找此项目跟目录位置
String path = t.substring(1, num).replace('/', '\\')+ "test\\static\\bat\\1.bat";写bat文件路径
String data ="\"C:\\Program Files\\MySQL\\MySQL Server 5.7\\bin\\mysqldump\" -u \"root\" -p\"root\" -P\"3306\" \"test\"> \""+ mysqlPathString + "\\" + fileNameString + ".sql\"";
//bat内容
data.replace("\'", "\"");
File txt = new File(path);
txt.createNewFile();创建文件
扫描二维码关注公众号,回复:
1907146 查看本文章
byte bytes[] = new byte[512]; bytes = data.getBytes();写文件
int b = data.length();
FileOutputStream fos = new FileOutputStream(txt);
fos.write(bytes, 0, b);
fos.close();
runtime.exec(path);