java program Inetaddress
<p>The question I have been asked is too
write java program that reads IP address from input file and writes the corresponding host names in the output file and vice versa.
here is my code:</p>

<pre><code>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
</code></pre>
