WAP to Getting FileStore information.

import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;

public class Test
 {
  static final long kiloByte = 1024;

  public static void main(String[] args) throws Exception
  {
    FileSystem fileSystem = FileSystems.getDefault();

    for (FileStore fileStore : fileSystem.getFileStores())
     {
      long totalSpace = fileStore.getTotalSpace() / kiloByte;
      long usedSpace = (fileStore.getTotalSpace() - fileStore
          .getUnallocatedSpace()) / kiloByte;
      long usableSpace = fileStore.getUsableSpace() / kiloByte;
      String name = fileStore.name();
      String type = fileStore.type();
      boolean readOnly = fileStore.isReadOnly();
    }
  }
}

Write a program to HTTP Grab with FileChannel.

import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

public class MainClass {

  public static void main(String[] args) throws IOException {

    URL u = new URL("http://www.java2s.com");
    String host = u.getHost();
    int port = 80;
    String file = "/";

    SocketAddress remote = new InetSocketAddress(host, port);
    SocketChannel channel = SocketChannel.open(remote);
    FileOutputStream out = new FileOutputStream("yourfile.htm");
    FileChannel localFile = out.getChannel();

    String request = "GET " + file + " HTTP/1.1\r\n" + "User-Agent: HTTPGrab\r\n"
        + "Accept: text/*\r\n" + "Connection: close\r\n" + "Host: " + host + "\r\n" + "\r\n";

    ByteBuffer header = ByteBuffer.wrap(request.getBytes("US-ASCII"));
    channel.write(header);

    ByteBuffer buffer = ByteBuffer.allocate(8192);
    while (channel.read(buffer) != -1) {
      buffer.flip();
      localFile.write(buffer);
      buffer.clear();
    }

    localFile.close();
    channel.close();
  }
}

Write a program to Save Web page to a file.

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

import javax.swing.text.html.parser.DTD;

public class MainClass
    {
     public static void main(String[] args)
     { 
     try
      {
      URL u = new URL("http://www.java2s.com");
      OutputStream out = new FileOutputStream("test.htm");
      InputStream in = u.openStream();
      DTD html = DTD.getDTD("html");
      System.out.println(html.getName());
      in.close();
      out.flush();
      out.close();
      } 
      catch (Exception e) {
      System.err.println("Usage: java PageSaver url local_file");
    }

  }

}

Write a program to check your own ip address...

import java.net.*;

class CheckIp
{
       public static void main(String args[])
      {
       try
       {
         InetAddress address=InetAddress.getLocalHost();
         System.out.println(address);
        }
     catch(UnknownHostException e)
   {
  System.out.println("could not find yahoo .com");
}
}
}

Write a program to comarision of two string.

class stringmethod
  {
    public static void main(String[] args)
      {
        String string1 = "Hi";
        String string2 = new String("Hello");
        if (string1 == string2)
           {
            System.out.println("The strings are equal.");
            }
        else
               {
                System.out.println("The strings are unequal.");
                }
        }
}               


Output of the program:-


The strings are unequal