Wed Oct 13 2021

Copy Data File

File Name: copy-data-file.java

/* 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!
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.