package applet;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/*
* 这个类是在屏幕上输出显示已经启动的windows服务。模拟在运行中输入 net start命令。
*/
public class Test {
public static void main(String[] args) throws IOException{
Process p = Runtime.getRuntime().exec("cmd.exe /c net start");
InputStream is = p.getInputStream();
InputStreamReader isr = null;
isr = new InputStreamReader(is,"GBK" );//"UTF-8"
int len = isr.read();
byte[] buff = new byte[len];
/**
* 将byte数组转化为char数组
*/
String str2 = new String(buff);
char[] ch2 = new char[str2.length()];
for(int i=0;i<str2.length();i++) {
ch2[i] = str2.charAt(i);
}
isr.read(ch2);
FileOutputStream fos = new FileOutputStream("c://start.txt");
/**
* 将char数组转化为byte数组
*/
String str = String.valueOf(ch2,0,ch2.length);
byte[] alpha = str.getBytes();
fos.write(alpha);
System.out.println(new String(alpha));
}
}