- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to mark the current position in this input stream
The method java.io.InputStream.mark() is used to mark the current position in this input stream. This method requires a single parameter i.e. the bytes that can be read before the position marked is invalidated.
A program that demonstrates this is given as follows −
Example
import java.io.FileInputStream; import java.io.InputStream; public class Demo { public static void main(String[] args) throws Exception { InputStream i = null; try { i = new FileInputStream("C://JavaProgram//data.txt"); System.out.println("Char : "+(char)i.read()); System.out.println("Char : "+(char)i.read()); System.out.println("Char : "+(char)i.read()); i.mark(0); System.out.println("Char : "+(char)i.read()); System.out.println("Char : "+(char)i.read()); if(i.markSupported()){ i.reset(); System.out.println("Char : "+(char)i.read()); System.out.println("Char : "+(char)i.read()); } } catch(Exception e) { e.printStackTrace(); } } }
The output of the above program is as follows −
Output
Char : D Char : A Char : T Char : A
- Related Articles
- Java Program to close this input stream and release any system resources associated with the stream
- Java Program to read the next byte of data from the input stream
- How to convert an input stream to byte array in java?
- Program to convert List to Stream in Java
- How to convert/read an input stream into a string in java?
- Java Program to convert Stream to List
- Program to convert Primitive Array to Stream in Java
- Program to convert Stream to an Array in Java
- Program to convert Boxed Array to Stream in Java
- Java Program to set title position in Java
- Java Program to convert Stream to typed array
- Standard Input Stream (cin) in C++
- Program to convert a Map to a Stream in Java
- Program to convert a Set to Stream in Java using Generics
- Array To Stream in Java

Advertisements