Java's InputStream
and OutputSteam
are both abstract classes that are used to access the underlying dataset. They are APIs that define operations for specific data sequences, implemented through a series of steps. InputStream
Rearrange the dataset into an ordered stream of bytes to read data from a file or network. Returns -1 at the end of the stream (Java does not have unsigned byte data type). OutputStream
then receives output bytes and writes them to the target. It is the most basic method of writing a single byte output. This article will compare the differences between these two streams and explain them in combination with practical applications.
FileOutputStream fileOut = new FileOutputStream("ARBRDD.txt");
<code>file is successfully updated today!!</code>
InputStream
and OutputStream
Features |
|
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Data Read/Write | Use read() , read(byte[]) , read(byte[], int, int) /td>
| Write data using write(int) , write(byte[]) , write(byte[], int, int) |
|||||||||||||||
Data flow | Data flows from source to application | Data flows from application to target | |||||||||||||||
Data Type | Readable bytes | Writable bytes, characters, or objects (using subclasses) | |||||||||||||||
Data connection | You can use FileInputStream or ByteArrayInputStream to connect to existing data |
You can use FileOutputStream or ByteArrayOutputStream to connect to existing data |
Use the FileInputStream
and FileOutputStream
functions.
This algorithm describes the workflow of the stream class. First declare and set the insertion order (for example, using the timer class). The input result is then evaluated by iterating length traversal.
Syntax explains how to declare a process as null to mark and skip the Boolean process. After that, we will reset the process to track the stack value by forcing the exception class.
FileOutputStream fileOut = new FileOutputStream("ARBRDD.txt");
FileInputStream
and FileOutputStream
Methods This method uses the FileInputStream
and FileOutputStream
methods to perform streaming on the collection.
This code uses a text file to write a string to it through a Java stream function. A catch block is declared in this process to handle the exception.
<code>file is successfully updated today!!</code>
public class NewClass { public static void main(String[] args) throws Exception { InputStream processARBRDD = null; try { processARBRDD = new FileInputStream("FILE_NAME.txt"); // PRINT METHOD processARBRDD.mark(0); processARBRDD.skip(1); // PRINT METHOD boolean check = processARBRDD.markSupported(); if (processARBRDD.markSupported()) { processARBRDD.reset(); // PRINT METHODS } else { // PRINT METHODS } } catch (Exception excpt) { excpt.printStackTrace(); } finally { if (processARBRDD != null) { processARBRDD.close(); } } } }
ByteArray
Stream is used to write data to a byte array. In this topic, we use different stream functions to establish connections between data and code.
The above is the detailed content of Difference Between InputStream and OutputStream in Java. For more information, please follow other related articles on the PHP Chinese website!