The basic idea of IOStreams is
- Storing and reading data from files
- reading data from keyword
- The environment that allows us to store data permanently is called persistent media.
- We can store data permanently in three places
- Remote Computer
- The process of storing data permanently in a persistence media.
- The logic that persist data in a persistence media is called persistence logic.
- Ex: IOStreams based logic, JDBC logic, Networking based logic.
- The technology that provides API to develop persistence logic is called persistence technology.
- Well known persistence technologies are
- IOStreams : to persist data in files
- JDBC, EJB, Hibernate: to persist data in db
- Networking: to persist data in remote computer
Where can we store data permanently?
- In persistence medias either files or in databases.
- Storing data in variables and arrays is temporary. Data will be lost when a local variable goes out of scope or when the program terminates.
- programmers use files or databases for long term storage of large amount of data. it is available even after termination of the program. We refer to data maintained on files as persistent data, because the data exists beyond the duration of the program execution.
- To store data in files and databases Oracle has given in built API. We all need to do is creating the particular class object calling methods for storing and reading data from that persistence media.
- IOStreams API is given to store and read data from files
- JDBC API is given to store and read data from Databases.
How java application can store or read data from a file?
- Using stream object.
Introduction to Streams:
- Stream is logical connection between java program and a file.
- To store the data in the persistence media there should be a way to connect to persistence media from java application either physically or logically. Stream provides logical connection.
- "Its a continuous flow of data between java program and persistence media"
Direction of stream flow:
- Stream has a direction and its direction depends on the viewer's view. In java the viewer is java Application. If you look from Java Application it is sending out from Java Application.
Type of Streams:
- Generally Streams are divided in to two types based on data flow direction.
- The stream that allows data to come into the java application from the persistent media is called input Stream.
- The stream that allows data to send out from the java application to be stored into the persistence media is called OutPutStream.
- Basically InputStreams are used to read data from a persistence media , and Oputstreams are used to write or store data in a persistence media from a java application
Types of Java Streams:
- In java we are allowed to send data through streams only either in the format of bytes or characters. So based on the type of the data passed through streams .
- In java streams are divided in to two types.
- Binary Streams.
- Character Streams.
- The streams which read and write data in the format of bytes is called Character streams.
- The streams which read and write data in the format of characters is called Character streams.