java 调用cmd 管理员权限_java window7 以上的操作系统调用cmd需要超级管理员怎么解决在线等。...

publicvoiddbf(HttpServletRequestrequest,HttpServletResponseresponse){try{response.setCharacterEncoding("utf-8");response.setHeader("content-disposition","attachment;filen...

public void dbf (HttpServletRequest request,HttpServletResponse response){

try {

response.setCharacterEncoding("utf-8");

response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode("mydata.sql", "UTF-8"));

Runtime rt = Runtime.getRuntime();

String sPath = this.getClass().getResource("/db.properties").getPath() ; //文件路径

String xPath = this.getClass().getResource("/mysqldump.exe").getPath() ; //文件路径

String xxPath = xPath.substring(1);

String dbname = GetProperties.getValue(sPath, "dbname");

String dburl = GetProperties.getValue(sPath, "dburl");

String username = GetProperties.getValue(sPath, "username");

String password = GetProperties.getValue(sPath, "password");

String port = GetProperties.getValue(sPath, "port");

String cmd = "cmd.exe /c "+xxPath+" -h"+dburl+" -P"+port+" -u"+username+" -p"+password+" "+dbname;

Process process=rt.exec(cmd); //C:\\mysqldump\\mysqldump

String line;

InputStreamReader isr = new InputStreamReader(process.getErrorStream());

LineNumberReader input = new LineNumberReader(isr);

while((line = input.readLine())!= null){

System.out.println(line+"~~~~~~~~~~");

}

InputStream in = process.getInputStream();

System.out.println(in.toString());

InputStreamReader xx = new InputStreamReader(in, "utf8");

OutputStream out = null;

int len = 0;

byte[] buffer = new byte[1024];

out = response.getOutputStream();

while((len = in.read(buffer)) > 0) {

out.write(buffer,0,len);

}

out.flush();

out.close();

in.close();

System.out.println(cmd);

System.out.println(sPath);

System.out.println(xPath);

System.out.println(dbname);

System.out.println(dburl);

System.out.println(username);

System.out.println(password);

System.out.println(port);

} catch (IOException e) {

System.out.println("备份失败!");

e.printStackTrace();

}

}

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值