Mon Oct 11 2021

Copy Byte File

File Name: copy-byte-file.java

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

class copybytesfile {
	public static void main(String args[ ]) throws IOException {
		FileOutputStream fileOut;
		FileInputStream fileIn;
		byte text;
		try {
			fileIn = new FileInputStream("bytefile.txt");
			fileOut = new FileOutputStream("tofile.txt");

			/* Reading and writing bytes */
			do {
				text = (byte) fileIn.read();
				fileOut.write(text);
			}
			while(text != -1);
			fileIn.close();
			fileOut.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.