File Copy in Java : File Commands : File Input Output : Java examples (example source code) Organized by topic

Java
C++
PHP
Java Home »  File Input Output   » [  File Commands  ]  Screenshots 
 



File Copy in Java

/* From http://java.sun.com/docs/books/tutorial/index.html */

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Copy {
  public static void main(String[] argsthrows IOException {
    File inputFile = new File("farrago.txt");
    File outputFile = new File("outagain.txt");

    FileReader in = new FileReader(inputFile);
    FileWriter out = new FileWriter(outputFile);
    int c;

    while ((c = in.read()) != -1)
      out.write(c);

    in.close();
    out.close();
  }
}

           
       
Related examples in the same category
1.  Counts words in a file, outputs results in sorted form
2.  Copying a file using channels and buffers
3.  Copy files using Java IO API Copy files using Java IO API
4.  Mimic the Unix Grep command
5.  File concatenation
6.  Compress files using the Java ZIP API
7.  Delete file using Java IO API
8.  Undent - remove leading spaces
9.  TeePrintStream tees all PrintStream operations into a file, rather like the UNIX tee(1) command
10.  Delete a file from within Java, with error handling
11.  DirTree - directory lister, like UNIX ls or DOS and VMS dir DirTree - directory lister, like UNIX ls or DOS and VMS dir
12.  Program to empty a directory
13.  Report on a file's status in Java
14.  Simple directory lister
15.  Readonly Files
16.  List root directory List root directory
17.  Rename a file in Java
18.  FNFilter - directory lister using FilenameFilter
19.  mkdir examples
20.  Program to remove files matching a name in a directory
21.  Ls directory lister modified to use FilenameFilter Ls directory lister modified to use FilenameFilter
22.  Dir Stack Dir Stack
23.  Word Count
24.  Diff: text file difference utility. Diff: text file difference utility.
25.  Count chars in a File








Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.