我一直在問的問題太 寫java程序,它從輸入文件中讀取IP地址,並在輸出文件中寫入相應的主機名,反之亦然。 這裏是我的代碼:java程序Inetaddress
import java.net.*;
import java.io.*;
public class hw
{
public static void main(String args[])
{
try{
FileReader f= new FileReader("w.txt");
BufferedReader r = new BufferedReader(f);
FileWriter o = new FileWriter("out.txt");
PrintWriter p = new PrintWriter(o);
String line = r.readLine();
String hn=line;
String IP;
InetAddress d=InetAddress.getByName(hn);
while(line !=null)
{
hn=d.getByName(line);
p.println(hn);
IP=d.getHostName();
p.println(IP);
}
r.close();
p.close();
}
catch(FileNotFoundException e)
{System.out.println("file not found");}
catch(IOException e)
{System.out.println("io error "+e.getMessage());}
}//main
}//class
,什麼是你的問題?這是否編譯?它是否會拋出異常?它工作嗎? – 2011-03-07 15:21:08