DataInputStream类skipBytes()方法 (DataInputStream Class skipBytes() method)

  • skipBytes() method is available in java.io package.

    skipBytes()方法在java.io包中可用。

  • skipBytes() method is used to skip the given number of bytes of data from this DataInputStream.

    skipBytes()方法用于从此DataInputStream跳过给定数量的数据字节。

  • skipBytes() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    skipBytes()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • skipBytes() method may throw an exception at the time of skipping bytes of data.

    skipBytes()方法在跳过数据字节时可能会引发异常。

    IOException: This exception may throw when getting any input/output error.

    IOException :遇到任何输入/输出错误时,可能引发此异常。

Syntax:

句法:

    public final int skipBytes(int number);

Parameter(s):

参数:

  • int number – represents the number of bytes to be skipped.

    int number –表示要跳过的字节数。

Return value:

返回值:

The return type of the method is int, it returns the exact number of bytes to be skipped.

方法的返回类型为int ,它返回要跳过的确切字节数。

Example:

例:

// Java program to demonstrate the example
// of int skipBytes(int number) method of
// DataInputStream
import java.io.*;
public class SkipBytesOfDIS {public static void main(String[] args) throws IOException {InputStream is_stm = null;
DataInputStream dis_stm = null;
FileOutputStream fos_stm = null;
DataOutputStream dos_stm = null;
byte[] b_arr = {12,
20,
45,
98,
75,
69,
30,
58,
47,
61,
83,
55
};
try {// Instantiate FileInputStream,
// DataInputStream, FileOutputStream
// and DataOutputStream
fos_stm = new FileOutputStream("C:\\Users\\Preeti Jain\\Desktop\\programs\\includehelp.txt");
dos_stm = new DataOutputStream(fos_stm);
// Loop to write each byte till end
for (byte val: b_arr) {// By using write() method isto
// write a byte value to the
// DataOutputStream dos_stm
dos_stm.write(val);
}
is_stm = new FileInputStream("C:\\Users\\Preeti Jain\\Desktop\\programs\\includehelp.txt");
dis_stm = new DataInputStream(is_stm);
// Loop To Read Available Data till end
while (dis_stm.available() > 0) {// By using skipBytes() method is to
// skip 2 bytes of data from the stream
dis_stm.skipBytes(2);
// By using read() method isto read
// byte from dis_stm
int in = dis_stm.read();
System.out.println("dis_stm.read(): " + in );
}
} catch (Exception ex) {System.out.println(ex.toString());
} finally {// To free system resources linked
// with these streams
if (is_stm != null)
is_stm.close();
if (dis_stm != null)
dis_stm.close();
if (dos_stm != null)
dos_stm.close();
if (fos_stm != null)
fos_stm.close();
}
}
}

Output

输出量

dis_stm.read(): 45
dis_stm.read(): 69
dis_stm.read(): 47
dis_stm.read(): 55

翻译自: https://www.includehelp.com/java/datainputstream-skipbytes-method-with-example.aspx

Java DataInputStream skipBytes()方法与示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. inputstream 关闭 java,Java ObjectInputStream close()方法与示例

    ObjectInputStream类close()方法close()方法在java.io包中可用. close()方法用于关闭此ObjectInputStream并释放与此流链接的所有系统资源. cl ...

  3. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  4. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  5. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  6. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  7. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  8. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

  9. java arraylist.add(),Java ArrayList add()方法与示例

    ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...

最新文章

  1. 7步搞定Python数据可视化,业界大牛出品教程,Jupyter、Colab都有在线版
  2. 【自然语言处理】自然语言处理(NLP)知识结构总结
  3. 微信小程序 与后台服务器交互,微信小程序 与后台交互----传递和回传时间
  4. python设置函数执行时间
  5. 网络协议之:还在用HTTP代理?过时了,快试试SOCKS5
  6. 华三交换机接口配置access_二层交换——交换机的基础和VLAN
  7. 使用Degraph管理软件包依赖关系
  8. 前端学习(2133):前端代码复杂带来的问题
  9. iOS面试中经常问的点 - RunTime
  10. Linux内核性能架构:perf_event
  11. java地铁最短,地铁最短路径
  12. 017指北与游移方位惯导系统知识梳理
  13. 黑群晖 7.0 安装
  14. ADByby 自定义过滤语法简表
  15. Linux之父:不担心微软接管Linux
  16. 如何做到像使用 LaTeX 那样优雅地使用 Word?
  17. 外挂原理之植物大战僵尸
  18. 基于LeNet的手写汉字识别(caffe)
  19. betaflight 10.8.0_win10调试笔记(未完待续)
  20. (三)51单片机基础——独立按键与数码管

热门文章

  1. php+mysql记事本_一个简单记事本php操作mysql辅助类创建
  2. linux课堂笔记(8)
  3. linux流式访问日志,流式实时日志分析系统的实现原理
  4. php如何加密图片,php实现图片加密解密,支持设置密码 (两年后版本!)
  5. 通过脚本启动批量服务
  6. 腾讯云服务器 ubuntu 设置允许root用户登录和禁用ubuntu用户
  7. 机器学习(一)梯度下降算法的实现及过程分析
  8. 可视化数据包分析工具-CapAnalysis
  9. 多线程基础(二)pthread的了解
  10. VSTO应用程序中加入键盘钩子