通过调用windows的外部命令rasdial
裏面的connectionName需要改成你自己的连接名称(一般默认是宽带连接)
如果名称中带空格就给connctionName前后加上引号。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) throws Exception {
try {
String connectionName = "宽带连接";
Process pro = Runtime.getRuntime().exec(
"rasdial " + connectionName + " /DISCONNECT");
BufferedReader br = new BufferedReader(new InputStreamReader(pro
.getInputStream(), "GBK"));
String msg = null;
while ((msg = br.readLine()) != null) {
System.out.println(msg);
}
} catch (IOException exception) {
}
}
}