 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can read and write binary values into files in Java. Before starting, you can click on the link which is available at bottom right corner of this video so that you can subscribe my YouTube channel. If you want to download my app Takimiz that is available on Google Play, you can note this name. You can connect with me by following these details which are available in front of you. Now coming on to the topic, reading and writing binary values. So friends, there are various data types available in Java for reading or writing these data type values. You can use following methods which are available or listed in front of you. For reading, you can use read boolean, read care, read byte, read short, read int, read long, read float, read double, read line. These are reading methods for various data types. Similar to reading, there are write methods which are write boolean and for writing we have to pass an argument also. And while you are reading any value, then they will return specific type of value which you want to read. Now I am going to demonstrate you how this is possible in Java with the help of program. So first I am writing some binary values. You can see this code. Here Java.io package is imported. Name of classes file write which is user defined. Then main method is implemented. Here through clause is available which is showing IO exception. Here if any input output exception will be raised, then I am not handling that exception using try and catch. I am throwing this exception so that caller of main method will be handling that exception and caller of main is JVM. So if I write through IO exception, then any exception which is raising in this code will be handled by the JVM. Then file output stream object FOS is created which is linked with file.et. This file will be opened in write mode. Then data output stream object DOS is created which is linked with FOS file output stream. So whenever you want to write binary values, you have to create an object of data output stream class. Then with the help of DOS dot write Boolean, I am writing true. Then with the right end, I am writing integer with right float. I am writing float values. You can see that 23.456 f f is indicating that it is a float value. If you remove this f, then this value will be converted into double. Then after writing operation, DOS is closed and FOS is closed. Now this file is saved in the project which is named as Sanjay. So first we have to check that whether this file is created or not. So I am opening location D practice inside practice folder. This this project is available and you can see no TXT file is available here. Now I am executing this code. It is executed. Now we have to check that whether the file is created or not. It is created and I am opening this file. You can see binary values are available here that you can't understand. So I am closing this file. Now if you want to understand what contains are available in that file, then you have to create another Java code that is for reading that file. So again here I have imported IO dot star IO package and its classes. Then user defined classes read file. Main method is throwing IO exception so that any exception will be handled by the JVM. Then file input stream object is created. Here this file dot txt is linked to read the contents which are available in this file. And data input stream is used here in previous example. I have used file output and data output streams. Right now I am using file input and data input streams. Data input stream object is linked with file input stream object. Now with the help of this DIS object, I can read Boolean, read integer and read float. So read Boolean is returning Boolean value. Read integer is returning integer value and read float is returning float value. Now you have to remember that in which order you have stored the values. So order was Boolean int and float. So in same order you have to read the values. If you change the order then garbage values will be received and your outputs will be incorrect. Now if you want to display these values to user, you can use system.out.println. So this is printing B, I and F variables on console. Then DIS is closed and FIS is closed. So with the help of this, I can display the contents which are available in file.txt. Now I am executing this code. You can see Boolean equals to true, integer equals to 1, 2, 3, 4 and float equals to 2, 3.456. These values are displayed here, which I have stored with the help of this file write class. So same values are displayed with the help of this read file class. So friends, this way you can implement programs in Java so that you can store binary values. You can read, you can use other read and write methods also which are listed here. So I hope you have understood how you can read and write binary values in files using file handling concept of Java. If you want to watch more programming related videos, you can subscribe my YouTube channel. Thank you for watching this video.