Read and Write Files in Java
Here is a sample code I just wrote. This class copies one file to another. By understanding this code below , you will comphrend both reading from and writing to file concepts in java. I used FileInputStream and FileOutputStream in this code. package javacream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class FileUtil { public static void copyFile(String strInputFileName , String strOutputFileName) throws IOException { //Prepare file objects File fInputFile = new File(strInputFileName); File fOutputFile = new File(strOutputFileName); //Prepare read write streams from file objects FileInputStream fis = new FileInputStream(fInputFile); FileOutputStream fos = new FileOutputStream(fOutputFile); int c; // read from the input file and write to the output file while ((c = fis.read()) != -1) { ...