Wed Oct 06 2021

Byte File

File Name: byte-file.java

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

class bytefile {
	public static void main(String args[ ]) throws IOException {

		/* Declare and create input file */
		FileOutputStream filewrite = new FileOutputStream("bytefile.txt");
		byte txt[]={'T','h','i','s', '\n', 'i','s','\n','B','y','t','e','\n','F','i','l','e'};
		filewrite.write(txt);
		System.out.println("File Created!\n");
		filewrite.close();

		/* Read till end of the file */
		FileInputStream fileread = new FileInputStream("bytefile.txt");
		int rf;
		System.out.println("Reading File -");
		while((rf = fileread.read()) != -1)
			System.out.print((char) rf);
		System.out.println();
		fileread.close();
	}
}



/* Output */
File Created!

Reading File -
This
is
Byte
File

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