Posts

Showing posts with the label Java File stream

mathajax

Java File Write Operation

The Java program explains how to write text content into a new file on the disk using the FileOutputStream object which has different write functions operation. The following basic file operation used in this program. File Create File write operation in Java is done while creating an instance/object to the FileOutputStream by invoking constructor function with filepath a as argument. If the file is already found on specified file path, The FileOutputStream object truncates content of the file. File Write and close After creating an instance of the FileOutputStream class, it supports file write and close operation and also supports three ways of writing bytes into the file. They are, write single byte , write the array of bytes with its index and length and write all bytes in an array into the file The Java program is an example of write a byte into the file. The byte is read from user through keyboard. import java.io.FileOutputStream; import ...

Java File Read Operation

The Java program explains how to read content from a file on the disk using the FileInputStream object having different read function operations. The following basic file operation used in these program. File Open File open operation in Java is done while creating an instance/object to the FileInputStream by invoking constructor function with filepath a as argument.if the file is not found on specified file path, FileInutStream class throws an exception called FileNotFoundException. File Read & close After creating an instance of the FileInputStream class, they supports file read and close operation and also supports three ways of reading data from the file.They are, read a byte , read array of byte and read all bytes from the file . The Java program is an example of reading content from a file on the disk in the manner of reading a single byte by one read operation. At the end of file, the read function returns -1. import java.io.File...