Byte File

/* 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

Comments (0)

  • To add your comment please or

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

Got It!