折中,调用一个CMD命令,执行重启程序,即
Runtime.getRuntime().exec("....")
在exec中执行一个批处理命名 ,杀掉当前java程序后再重新启动。
电脑重启么????
processbuiler,process,执行doc命令即可,so easy
给你,小挫import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.File
import java.io.IOException
import java.io.InputStreamReader
import java.io.OutputStreamWriter
public class Processing
{
public static void main ( String[] args )
{
try
{
// open cmd
// Process process = Runtime.getRuntime ().exec (new String[] {
// "cmd", "/c", "dir" }, null, new File ("e:/"))
Process process = Runtime.getRuntime ().exec ("cmd")
InputStreamReader isr = new InputStreamReader (process.getInputStream (), "gbk")
BufferedReader br = new BufferedReader (isr)
// next command
OutputStreamWriter osw = new OutputStreamWriter (process.getOutputStream ())
BufferedWriter bw = new BufferedWriter (osw)
bw.write ("shutdown -r -f")
bw.newLine ()
bw.flush ()
bw.close ()
osw.close ()
// read
String line = null
while (null != ( line = br.readLine () ))
{
System.out.println (line)
}
// wait for termination
// process.waitFor ()
// process.exitValue ()
process.destroy ()
br.close ()
isr.close ()
}
catch (IOException e)
{
e.printStackTrace ()
}
// catch (InterruptedException e)
// {
// e.printStackTrace ()
// }
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)