java调用mysql后乱符_Java Process exec方法调用mysqldump读取output不完整 -w导致

我估计是标准输出缓冲区已经满了的缘故,这错误输出缓冲区和标准输出缓冲区如果填满的情况下是会阻塞JAVA线程的。

在你的类中加入如下代码:static class StreamGobbler extends Thread

{

InputStream is;

String type;

StringBuffer info;

StreamGobbler(InputStream is, String type,StringBuffer info)

{

this.is = is;

this.type = type;

this.info=info;

}

public void run()

{

try

{

InputStreamReader isr = new InputStreamReader(is);

BufferedReader br = new BufferedReader(isr);

String line=null;

while ( (line = br.readLine()) != null)

info.append(type + ">" + line);

} catch (Exception ioe)

{

ioe.printStackTrace();

}

}

}

public void rumCommand(String cmd) {

Runtime runtime = Runtime.getRuntime();

String cr=System.getProperty("line.separator");

StringBuffer output=new StringBuffer();

StringBuffer err=new StringBuffer();

int exitValue=0;

try {

Process proc = runtime.exec(cmd);

// put a BufferedReader on the ls output

StreamGobbler sgStd=new StreamGobbler(proc.getInputStream(),"STDOUT",output);

StreamGobbler sgErr=new StreamGobbler(proc.getErrorStream(),"ERROUT",err);

sgStd.start();

sgErr.start();

exitValue=proc.waitFor();

} catch (IOException e) {

logger.debug(e);

} catch (InterruptedException e) {

logger.debug(e);

}

}

你自己的代码只要使用:

runCommand(dumpCommand);

参考:http://hellsing42.iteye.com/blog/118317

2008年7月22日 15:44

e147a9a9d9ebeb523edb06ce9032e774.png

821

0

0

4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值