InputStream类skip()方法
- skip() 方法可在java.io包。
- skip() 方法用于从该 InputStream 跳过给定字节数的数据。
- skip() 方法是一个非静态方法,它只能通过类对象访问,如果我们尝试使用类名访问方法,那么我们将得到一个错误。
- skip() 方法可能会在跳过字节数据时抛出异常。
 IOException:在执行时遇到任何输入/输出错误时可能会抛出此异常。
用法:
public long skip(long number);
参数:
- long number– 表示要跳过的字节数。
返回值:
该方法的返回类型是long,它返回跳过的确切字节数。
例:
// Java program to demonstrate the example 
// of long skip(long number) method 
// of InputStream
import java.io.*;
public class SkipOfIS {
 public static void main(String[] args) throws Exception {
  InputStream is_stm = null;
  try {
   // Instantiates FileInputStream
   is_stm = new FileInputStream("D:\\includehelp.txt");
   for (int val = 0; val < 8; ++val) {
    // By using read() method is to read
    // a byte from is_stm
    is_stm.read();
    // Display corresponding bytes value
    byte b = (byte) val;
    // Display value of b
    System.out.println("is_stm.read():" + b);
    // By using skip() method is to skip         
    // 1 bytes data from the is_stm
    long skip_byte = is_stm.skip(1);
    System.out.println("is_stm.skip(1):" + skip_byte);
    System.out.println();
   }
  } catch (Exception ex) {
   System.out.println(ex.toString());
  } finally {
   // with the help of this block is to
   // free all necessary resources linked
   // with the stream
   if (is_stm != null) {
    is_stm.close();
   }
  }
 }
}输出
is_stm.read():0 is_stm.skip(1):1 is_stm.read():1 is_stm.skip(1):1 is_stm.read():2 is_stm.skip(1):1 is_stm.read():3 is_stm.skip(1):1 is_stm.read():4 is_stm.skip(1):1 is_stm.read():5 is_stm.skip(1):1 is_stm.read():6 is_stm.skip(1):1 is_stm.read():7 is_stm.skip(1):1
相关用法
- Java InputStream available()用法及代码示例
- Java InputStream reset()用法及代码示例
- Java InputStream close()用法及代码示例
- Java InputStream mark()用法及代码示例
- Java InputStream markSupported()用法及代码示例
- Java InputStreamReader getEncoding()用法及代码示例
- Java InputStreamReader close()用法及代码示例
- Java InputStreamReader ready()用法及代码示例
- Java IntBuffer clear()用法及代码示例
- Java Inflater needsInput()用法及代码示例
- Java IntStream.Builder build()用法及代码示例
- Java IntSummaryStatistics getAverage()用法及代码示例
- Java Integer doubleValue()用法及代码示例
- Java Guava Ints lastIndexOf()用法及代码示例
- Java Instant query()用法及代码示例
- Java Inflater finished()用法及代码示例
- Java Instant plus()用法及代码示例
- Java Inflater getAdler()用法及代码示例
- Java IntBuffer mark()用法及代码示例
- Java IntBuffer equals()用法及代码示例
注:本文由纯净天空筛选整理自Preeti Jain大神的英文原创作品 Java InputStream skip() Method with Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
