用dos怎么删除java_谁知道怎么用java调用dos命令啊,在windows环境下,例如调用结束进程命令,做好有个小李子,谢谢了...

呵呵,我下午刚写了一个小程序,仅供参考!

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.IOException;

import java.util.Calendar;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class TestAutoShutDown {

public static void main(String[] args) {

// TODO Auto-generated method stub

AutoShutDown frame = new AutoShutDown();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.pack();

frame.setVisible(true);

}

}

class AutoShutDown extends JFrame {

private JLabel label;

private JTextField textField;

private JButton button;

private JPanel panel1;

public AutoShutDown(){

this.setTitle("自动关机");

label = new JLabel("分钟后关闭");

textField = new JTextField(8);

button = new JButton("确定");

button.addActionListener(new AutoCloseAction());

panel1 = new JPanel();

panel1.add(textField);

panel1.add(label);

panel1.add(button);

this.add(panel1);

}

class AutoCloseAction implements ActionListener{

private Calendar calendar;

@Override

public void actionPerformed(ActionEvent e) {

String time = textField.getText();

int timeInt = Integer.parseInt(time);

calendar = Calendar.getInstance();

calendar.add(Calendar.MINUTE, timeInt);

String closeTime = "at "+calendar.get(Calendar.HOUR_OF_DAY) +":"+ calendar.get(Calendar.MINUTE);

System.out.println(closeTime);

String operation = closeTime + " shutdown -s -t 5";

System.out.println(operation);

Runtime rt = Runtime.getRuntime();

try {

rt.exec(operation);

} catch (IOException e1) {

e1.printStackTrace();

}

}

}

}

取消

评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值