java执行exp导出命令_如何用JAVA调用本地EXP命令备份数据库?

在老外的网站上找到一个类可以实现:

import java.io.*;

/**

*  Description of the Class

*

* @author     Administrator

* @created    23 February 2004

*/

public class RunAsync {

/**

*  Description of the Method

*

* @param  args  Description of the Parameter

*/

public static void main(String args[]) {

try {

if (args.length < 1) {

System.out.println("Usage: java RunAsync &quot

9f7588d3b12cd5d674b5f81c0b8fc6cb.gif;

System.exit(-1);

}

Process pro = null;

if (args.length > 1) {

pro = Runtime.getRuntime().exec(args);

}

else {

pro = Runtime.getRuntime().exec(args[0]);

}

InputStream error = pro.getErrorStream();

InputStream output = pro.getInputStream();

Thread err = new Thread(new OutErrReader(error));

Thread out = new Thread(new OutErrReader(output));

out.start();

err.start();

pro.waitFor();

}

catch (java.io.IOException e) {

e.printStackTrace();

}

catch (java.lang.InterruptedException e) {

e.printStackTrace();

}

}

/**

*  Description of the Class

*

* @author     Administrator

* @created    23 February 2004

*/

static class OutErrReader implements Runnable {

InputStream is;

/**

*Constructor for the OutErrReader object

*

* @param  is  Description of the Parameter

*/

public OutErrReader(InputStream is) {

this.is = is;

}

/**

*  Main processing method for the OutErrReader object

*/

public void run() {

try {

BufferedReader in = new BufferedReader(new InputStreamReader(is));

String temp = null;

while ((temp = in.readLine()) != null) {

// System.out.println(temp);

Frame1.jTextArea1.append("\n&quot

9f7588d3b12cd5d674b5f81c0b8fc6cb.gif;

Frame1.jTextArea1.append(temp);

}

is.close();

}

catch (Exception e) {

e.printStackTrace();

}

}

}

}

我稍加修改了一下:

package oraclem;

import java.io.*;

public class RunCmd{

public static void run(String s){

try{    Process pro=Runtime.getRuntime().exec(s);

InputStream error=pro.getErrorStream();

InputStream output = pro.getInputStream();

NewThread err=new NewThread(error);

NewThread out=new NewThread(output);

err.start();

out.start();

pro.waitFor();

}catch (java.io.IOException e) {

e.printStackTrace();

}

catch (java.lang.InterruptedException e) {

e.printStackTrace();

}

}

}

class NewThread extends Thread{

InputStream is;

public NewThread(InputStream is){

this.is=is;}

public void run(){

try{BufferedReader in = new BufferedReader(new InputStreamReader(is));

String temp = null;

while ((temp = in.readLine()) != null) {

// System.out.println(temp);

Frame1.jTextArea1.append("\n&quot

9f7588d3b12cd5d674b5f81c0b8fc6cb.gif;

Frame1.jTextArea1.append(temp);

}

}catch (Exception e) {

e.printStackTrace();}

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值