当然可以
比如偶想执行copy命令:
如下:
String[] cmd = new String[3];
cmd[0] = "cmd.exe";
cmd[1] = "/C";
cmd[2] = "copy d:\\moduleExcel.xls d:\\tempModuleOfExcel.xls";
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);
比如偶想执行copy命令:
如下:
String[] cmd = new String[3];
cmd[0] = "cmd.exe";
cmd[1] = "/C";
cmd[2] = "copy d:\\moduleExcel.xls d:\\tempModuleOfExcel.xls";
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);
import java.awt.event.*;
import java.applet.*;public class myApplet extends Applet implements ActionListener
{
TextField t=new TextField(50);
Button button;
public void init()
{
button=new Button("确定");
add(button);
button.addActionListener(this);
add(t);
}
public void actionPerformed(ActionEvent event)
{
try{
String[] cmd = new String[3];
cmd[0] = "cmd.exe";
cmd[1] = "/C";
cmd[2] = "copy c:\\1.txt c:\\1\\";
t.setText(cmd[1]);
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);
}
catch(Exception e){}
}
}
在浏览器中嵌入此applet后,
<html>
<body>
<applet code="myApplet" codebase="." width="500" height="500">
</body>
</html>
打开浏览器执行,点击”确定“button,没有产生任何动作!!
请高手帮忙!
因为applet是不允许更改本地文件的。你可以参考一下policytool.exe的用法。:)