File Reading and Writing Example


/*
 * Reading and writing powerpoint file
 * and Reading and writing text file
 * using Java Program
 *
 */
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class TestPackageOutSide {

    public static void main(String[] args) {
     
        System.out.println("Out printed....");
     
        try {
         
            File infile =new File("c:/1.ppt");
            FileInputStream fin = new FileInputStream(infile);
            FileOutputStream fout = new FileOutputStream("c:/2.ppt");
            byte b[] = new byte[(int)infile.length()];
            fin.read(b);
            fout.write(b);
         
         
            /*
             *
          // Read and Write text data .
         //   File infile =new File("c:/Sample.java");
        FileReader fr = new FileReader(infile);
        //BufferedReader br = new BufferedReader(fr);
     
        FileWriter fw = new FileWriter("c:/BoxTest.java");      
        //  FileWriter fw = new FileWriter("c:/BoxTest.java",true);  // append content to file
        //PrintWriter pw = new PrintWriter(fw);
      //  BufferedWriter bw = new BufferedWriter(pw);
        char cbuf[] = new char[(int)infile.length()];
         
         fr.read(cbuf);
        fw.write(cbuf);
     
        //br.close();
        fr.close();
       //pw.close();
       // bw.close();
            fw.close();
        */
     
        } catch (Exception e) {
            System.out.println(e);
        }
     
     
    }
}

Comments

Popular posts from this blog

Custom Exception example for BankAccount

HashMap HashSet example

Annotation