Java Tutorial

 
 
 
 
import java.io.*;

class  CopyChar
{
    public static void main(String[] args) 
    {
           File infile = new File(\"infile.txt\");
           File outfile = new File(\"Outfile.txt\");
           FileReader fr=null;
           FileWriter fw=null;

           try{
                fr = new FileReader(infile);
                fw = new FileWriter(outfile);

               int ch;
               //FileReader Class which is subclass of InputSteamReader
               //InputStreamReader class converts Strings or character data
               //into Byte which are in form of integers. 
               //so ch is of int type

               while((ch=fr.read())!=-1){      //-1 indicates end-of-file (eof)
                   fw.write(ch);
               }

            }catch(IOException e)
            {
                  System.out.println(e);
                  System.exit(-1);
            }
            finally{
                 try{
                       fr.close();
                       fw.close();
                 }
                 catch(IOException e){}
            }

    }
}

    Related Post:
  1. Program to show the use of Logical OR Operator (|) in If Statements

  2. Program of an applet to illustrate BarChart

  3. Program to show the use of Conditional OR Operator (||) in If Statements

  4. Program to show an example of using initialization block to initialize the data members of a class

  5. program which takes a long sentence from the client passes to the server,server separates out each word and sends them back to client in reverse order

  6. An applet program that display blinking rectangle

  7. Program that will read real number from the keyboard and print the following output in one line: small Integer not less The Given Number Largest Int

  8. An applet program of passing parameters

  9. Program to print a string on Standard Output Device

  10. Program to show the use of If-Else Statement

  11. An applet program that displays random dot

  12. An applet program to draw different shapes

  13. Program to show an example of Arrays of String

  14. Program to read the ballots and count the votes cast for each candidate using an array variable count

  15. Program to show an example of overloading constructors in a class to initialize its data members

  16. Program to show the use of operator (>>) Shift Right, propagating the sign bit from the left

  17. Program to calculate the frequency for different values of C starting from 0.01 to 0.1 in steps of 0.01

  18. Corba program of UDP client server application which sends the news to the client. Server takes the news from the NewsDataFile located at the server

  19. Program to show an example of modifying String objects

  20. Program to show an example of creating a class and using its object

 
 
Didn't find what you were looking for? Find more on File handling program to copy characters from one file to another