//*****************************************************************************
// Read file and copy into another using Java "nio" package
// Entire file is read into a string and then written to another file                           
//*****************************************************************************
import java.nio.file.*;                             //import nio.file package

public class copyFile1   
{
    public static void main(String[] args)
    {
        try { 
            Path infile  = Paths.get("/home/sultans/web/java/demo/8inpout/data/temp.txt");
            Path outfile = Paths.get("/home/sultans/web/java/demo/8inpout/data/temp2.txt");

            //----READ---------------------
 
            byte[] allBytes = Files.readAllBytes(infile);       //read entire file into byte array 

            String str      = new String(allBytes);             //convert byte array into String                                                     

//          System.out.println(str);

            //----WRITE--------------------

            byte[] bytesArr = str.getBytes();                   //convert string into a byte array 

            Files.write(outfile, allBytes);                     //write entire byte array into file                                                     

            System.out.println("Copy Successful");
        }
        catch(Exception e) 
        {
           e.printStackTrace();                                //print trace dump
        }
    }    
}