Monday, October 22, 2012

Copy file in Java

Program to copy a file content in java is as follows:

 import java.io.*;

class FileCopy
{
  public static void main(String args[]) throws IOException
  {
    FileInputStream fin = new FileInputStream("d:/java/stk.java");
    FileOutputStream fout = new FileOutputStream("d:/java/txtfile.txt");
    int b;

    while(true)
    {
      b = fin.read();
      if(b == -1)
      {
        break;
      }
      System.out.print((char)b);
      fout.write(b);
    }

    fin.close();
    fout.close();
  }
}

No comments:

Post a Comment

MS SQL : How to identify fragmentation in your indexes?

Almost all of us know what fragmentation in SQL indexes are and how it can affect the performance. For those who are new Index fragmentation...