- 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
Advertisements