Java Programming

Copy Byte File

Java programming example for coping byte stream file from directory

10/11/2021
0 views
copy-byte-file.javaJava
/* 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!
Java TutorialCopy Byte FileCoping Byte Files

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com