Copy Data File

Java Programming

Java Programming Examples

/* Data stream */
import java.io.*;

class copydatafile {
	public static void main(String args[]) throws IOException {
		FileOutputStream wf;
		FileInputStream rf;
		try {
			wf = new FileOutputStream("outfile.txt");
			rf = new FileInputStream("infile.txt");
			DataOutputStream wd = new DataOutputStream(wf);
			DataInputStream rd = new DataInputStream(rf);
			
			/* Reading and writing file in 3 modes */
			wd.writeDouble(rd.readDouble());
			wd.writeInt(rd.readInt());
			wd.writeUTF(rd.readUTF());
			wd.close();
			wf.close();
			rd.close();
			rf.close();
			System.out.println("File Copied successfully!");
		}
		catch(FileNotFoundException e) {
			System.out.println("File not found!");
		}
	}
}


          /****** Output ******/
          

File Not found!




----------------------




File copied successfully!

Learn more about DataStream File