Java.io.InputStream.skip(long n) Method Example - TutorialsPoint
JAVA.IO.INPUTSTREAM.SKIP METHOD
Copyright ?
Description
The java.io.InputStream.reset method skips over and discards n bytes of data from this input stream.
Declaration
Following is the declaration for java.io.InputStream.skiplongn method:
public long skip(long n)
Parameters
n -- The number of bytes to be skipped.
Return Value
The actual number of bytes skipped.
Exception
IOException -- if an I/O error occurs, or if the stream does not support seek.
Example
The following example shows the usage of java.io.InputStream.skiplongn method.
package com.tutorialspoint;
import java.io.FileInputStream; import java.io.InputStream;
public class InputStreamDemo { public static void main(String[] args) throws Exception {
InputStream is = null; int i; char c;
try{ // new input stream created is = new FileInputStream("C://test.txt");
while((i=is.read())!=-1) {
// converts int to char c=(char)i;
// prints character System.out.println("Character Read: "+c);
// skip one byte is.skip(1); } }catch(Exception e){
// if any I/O error occurs e.printStackTrace(); }finally{
// releases system resources associated with this stream
if(is!=null) is.close();
} } }
Assuming we have a text file c:/test.txt, which has the following content. This file will be used as an input for our example program:
ABCDE
Let us compile and run the above program, this will produce the following result:
Character Read: A Character Read: C Character Read: E
Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- java files copyright © tutorialspoint
- exploring java i o unit 4 exploring java i o
- serial communication in java with example program idc online
- java s input output github pages
- long n method example tutorialspoint
- intermediate programming adelphi university
- java files and i o
- input output classes java and oop
- chapter 20 streams and binary input output
- binary i o university of california san diego