Tuesday, April 13, 2010

Displaying IP Address of the system using Runtime

Runtime is a class which is specifically made for the purpose to run any kind of process using "exec" method

import java.io.*;
class DisplayIP{
public static void main(String args[]){

Runtime runtime = Runtime.getRuntime();
try{
Process process = runtime.exec("cmd.exe /c ipconfig");
InputStream in = process.getInputStream();
int ch = in.read();
while(ch!=-1){
System.out.print((char)ch);
ch=in.read();
}
in.close();
}
catch(IOException e){
System.out.println(e);
}
}
}

Still any doubt !!! check out by clicking the link
http://www.java-tips.org/java-se-tips/java.util/from-runtime.exec-to-processbuilder.html
Cheers
Shyamala

No comments:

Post a Comment