Thursday, May 10, 2012

How to uninstall (GWT) Google Plugins from Eclipse?



Uninstall/update eclipse plugins

Uninstall Google Plugins from eclipse (Google Web Toolkit).

In Eclipse ,
Go to Help > About > Click on Installation Details


Select name of the software from the lists and click Uninstall button at the bottom as below image.


From here, we can install, update any eclipse plugins easily.

Wednesday, May 9, 2012

How to copy file in java with example

Here is the example of copying file in java. This example will copy file and its content from one file to another.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
 
public class CopyFileExample 
{
    public static void main(String[] args)
    { 
     InputStream inStream = null;
     OutputStream outStream = null;
     try
     {
         File fileOne =new File("D:\\db\\fileTest\\file2.txt");
         File fileTwo =new File("D:\\db\\fileTest\\file3.txt");
 
         inStream = new FileInputStream(fileOne);
         outStream = new FileOutputStream(fileTwo);
 
         byte[] buffer = new byte[1024];
          int length;
          
         //start copy file content in bytes 
         while ((length = inStream.read(buffer)) > 0)
         {
          outStream.write(buffer, 0, length);
         }
         inStream.close();
         outStream.close();
 
         System.out.println("File copied successfully");
     }
     catch(IOException e)
     {
      e.printStackTrace();
     }
    }
}

How to rename file in java with example

How to rename file in java with example
import java.io.File;

public class FileRenameExample 
{
    public static void main(String[] args)
    { 
 
  File oldFileName =new File("D:\\db\\fileTest\\file1.txt");
  File newFileName =new File("D:\\db\\fileTest\\file2.txt");
 
  if(oldFileName.renameTo(newFileName))
  {
   System.out.println("File Renamed successfully");
  }
  else
  {
   System.out.println("Can not rename file");
  }
    }
}

How to Delete file in Java with example

How to delete file in java code?
Here is the example of delete file operation

import java.io.File;

public class FileDeleteExample
{
    public static void main(String[] args)
    { 
     try
     {
      File file = new File("D:\\db\\fileTest\\file1.txt");
 
      if(file.delete())
      {
       System.out.println(file.getName() + " is deleted successfully");
      }
      else
      {
       System.out.println("Can not delete file");
      }
     }
     catch(Exception e)
     {
      e.printStackTrace();
     }
    }
}

How to add content, append content in File in Java with example using RandomAccessFile

How to Add content ot append content in existing file using RandomAccessFile in Java with Example
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Date;
 
public class ContentAppendToFileExample 
{
    public static void main( String[] args )
    { 
     try 
     {
     String contentToAddedAtTheEndOfFile = "\nThis content will added/append to the end of the file at "+new Date();
     File file =new File("D:\\db\\fileTest\\file1.txt");
         RandomAccessFile raf = new RandomAccessFile(file, "rw");

         // Seek to end of file
         raf.seek(file.length());

         // Append to the end
         raf.writeBytes(contentToAddedAtTheEndOfFile);
         raf.close();
     } 
     catch (IOException e) 
     {
      e.printStackTrace();
     }
    }
}