Friday 8 February 2019

Liked on YouTube: Java Input/Output Question Answer Quiz

Java Input/Output Question Answer Quiz

Java Input/Output Question Answer Quiz The java.io package contains nearly every class you might ever need to perform input and output (I/O) in Java. All these streams represent an input source and an output destination. The stream in the java.io package supports many data such as primitives, object, localized characters, etc. A stream can be defined as a sequence of data. There are two kinds of Streams − InPutStream − The InputStream is used to read data from a source. OutPutStream − The OutputStream is used for writing data to a destination. Streams Java provides strong but flexible support for I/O related to files and networks but this tutorial covers very basic functionality related to streams and I/O. We will see the most commonly used examples one by one − Byte Streams Java byte streams are used to perform input and output of 8-bit bytes. Though there are many classes related to byte streams but the most frequently used classes are, FileInputStream and FileOutputStream. Character Streams Java Byte streams are used to perform input and output of 8-bit bytes, whereas Java Character streams are used to perform input and output for 16-bit unicode. Though there are many classes related to character streams but the most frequently used classes are, FileReader and FileWriter. Standard Streams All the programming languages provide support for standard I/O where the user's program can take input from a keyboard and then produce an output on the computer screen. If you are aware of C or C++ programming languages, then you must be aware of three standard devices STDIN, STDOUT and STDERR. Similarly, Java provides the following three standard streams − Standard Input − This is used to feed the data to user's program and usually a keyboard is used as standard input stream and represented as System.in. Standard Output − This is used to output the data produced by the user's program and usually a computer screen is used for standard output stream and represented as System.out. Standard Error − This is used to output the error data produced by the user's program and usually a computer screen is used for standard error stream and represented as System.err. Reading and Writing Files As described earlier, a stream can be defined as a sequence of data. The InputStream is used to read data from a source and the OutputStream is used for writing data to a destination. FileOutputStream FileOutputStream is used to create a file and write data into it. The stream would create a file, if it doesn't already exist, before opening it for output. Here are two constructors which can be used to create a FileOutputStream object. Following constructor takes a file name as a string to create an input stream object to write the file − OutputStream f = new FileOutputStream("C:/java/hello") Following constructor takes a file object to create an output stream object to write the file. First, we create a file object using File() method as follows − File f = new File("C:/java/hello"); OutputStream f = new FileOutputStream(f); Once you have OutputStream object in hand, then there is a list of helper methods, which can be used to write to stream or to do other operations on the stream. Sr.No. Method & Description 1 public void close() throws IOException{} This method closes the file output stream. Releases any system resources associated with the file. Throws an IOException. 2 protected void finalize()throws IOException {} This method cleans up the connection to the file. Ensures that the close method of this file output stream is called when there are no more references to this stream. Throws an IOException. 3 public void write(int w)throws IOException{} This methods writes the specified byte to the output stream. 4 public void write(byte[] w) Writes w.length bytes from the mentioned byte array to the OutputStream. There are other important output streams available, for more detail you can refer to the following links − ByteArrayOutputStream DataOutputStream -~-~~-~~~-~~-~- interview question and answers https://www.youtube.com/watch?v=8dhBq_elHg8 interview question and answers https://www.youtube.com/watch?v=pC1mVWj9iq8&t=9s interview question and answers https://www.youtube.com/watch?v=3WuliE8Jmt0&t=6s interview question and answers https://www.youtube.com/channel/UCyNJURC5bvqIQ9vO9PBrYrA/videos?view_as=subscriber interview question and answers https://www.youtube.com/watch?v=6Z5OzXzQqUM&t=5s interview question and answers https://www.youtube.com/watch?v=Max8PhFkWtg&t=4s interview question and answers https://www.youtube.com/watch?v=Xd7Yk4vEpuo&t=7s interview question and answers https://www.youtube.com/watch?v=yc3V4pXPEpk Please watch: "Html interview questions and answers for freshers" https://www.youtube.com/watch?v=8dhBq_elHg8 -~-~~-~~~-~~-~-
via YouTube https://youtu.be/-zm__l2cdSg

No comments:

Post a Comment

😍Developer on Weekends #shorts #officememes #developermemes

😍Developer on Weekends #shorts #officememes #developermemes Welcome to the latest viral YouTube shorts meme for developers! 😍Developer on...