Java RandomAccessFile seek()方法与示例

RandomAccessFile类seek()方法 (RandomAccessFile Class seek() method)

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

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

  • seek() method is used to sets the file pointer position calculated from the starting of this file at which the next read or write operation occurs and the position might be set beyond the file.

    seek()方法用于设置从该文件的开头算起的文件指针位置,在该文件开始下一次读取或写入操作时,该位置可能会设置在文件之外。

  • seek() 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.

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

  • seek() method may throw an exception at the time of seeking file pointer.

    seek()方法在查找文件指针时可能会引发异常。

    IOException: This exception may throw an exception while performing input/output operation.

    IOException :在执行输入/输出操作时,此异常可能会引发异常。

Syntax:

句法:

    public void seek(long pos);

Parameter(s):

参数:

  • long pos – represents the offset location at which to set file pointer, measured in bytes from the beginning of the file.

    long pos –表示设置文件指针的偏移位置,以从文件开头开始的字节数为单位。

Return value:

返回值:

The return type of this method is void, it returns nothing.

此方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example 
// of void seek(long pos) method of
// RandomAccessFile
import java.io.*;
class RAFSeek {
public static void main(String[] args) throws Exception {
// Instantiate a random access file
// object with file name and permissions
RandomAccessFile ra_f = new RandomAccessFile("e:/includehelp.txt", "rw");
// By using writeUTF() method is to 
// write data to the file
ra_f.writeUTF("Welcome in Java World!!!");
// by using seek() method is to 
// set the current file indicator
// from where read/write could 
// start i.e. we set here 0 so reading
// will be done from 0 till EOF
ra_f.seek(0);
// By using readUTF() method is to 
// read a data in a string from
// this file
//String str = ra_f.readUTF();
System.out.println("ra_f.readUTF(): " + ra_f.readUTF());
// By using close() method isto
// close this stream ran_f
ra_f.close();
}
}

Output

输出量

ra_f.readUTF(): Welcome in Java World!!!

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541664.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Javascript开发技巧(JS中的变量、运算符、分支结构、循环结构)

一、Js简介和入门 继续跟进JS开发的相关教程。 <!-- [使用JS的三种方式] 1、HTML标签中内嵌JS&#xff08;不提倡使用&#xff09;&#xff1a; 示例&#xff1a;<button οnclick"javascript:alert(你真点啊&#xff01;)">有本事点我呀&#xff01;&#…

android 颜色范围,Android系统颜色的适用范围

###All Clickable Views:ripple effect (Lollipop only) — “colorControlHighlight”###Status Bar:background (Lollipop only) – “colorPrimaryDark”###Navigation Bar:background (Lollipop only) – “android:navigationBarColor”###EditText:underline (unfocused)…

bytevalue_Java Short类byteValue()方法及示例

bytevalue短类byteValue()方法 (Short class byteValue() method) byteValue() method is available in java.lang package. byteValue()方法在java.lang包中可用。 byteValue() method is used to return the value denoted by this Short object converted to type byte (by …

分布式交换机配置备份和还原

1.备份和还原vSphere Distributed Switch配置 1.1导出 vSphere Distributed Switch 配置 可以将 vSphere Distributed Switch 和分布式端口组配置导出到某一文件。该文件保留有效的网络配置&#xff0c;使这些配置能够传输至其他环境。 步骤&#xff1a; 1) 在 vSphere Web Cli…

html自动执行函数,JS 自执行函数原理及用法

js自执行函数&#xff0c;听到这个名字&#xff0c;首先会联想到函数。接下来&#xff0c;我来定义一个函数&#xff1a;function aaa(a,b){return sum a b}定义了一个名为aaa的函数&#xff0c;在里面可以计算两个数的和。如果想执行它&#xff0c;就必须得调用它&#xff0…

java reverse_Java Integer类reverse()方法与示例

java reverse整数类reverse()方法 (Integer class reverse() method) reverse() method is available in java.lang package. reverse()方法在java.lang包中可用。 reverse() method is used to returns the value generated by reversing the order of bits in binary 2s comp…

华为鸿蒙系统好在哪,华为鸿蒙2.0可以替代安卓吗,华为鸿蒙2.0优势在哪

在华为开发者大会上&#xff0c;华为消费业务CEO 余承东&#xff0c;正式发布鸿蒙OS2.0&#xff0c;并宣布华为鸿蒙OS将全面启用全场景生态&#xff0c;并将于2020年12月发布手机版。余承东还表示&#xff0c;明年&#xff0c;华为的智能手机将全面升级&#xff0c;以支持鸿蒙操…

Java GregorianCalendar add()方法与示例

GregorianCalendar类的add()方法 (GregorianCalendar Class add() method) add() method is available in java.util package. add()方法在java.util包中可用。 add() method is used to add the given quantity to the specified GregorianCalendar field (fi). add()方法用于…

JVM(三)——对象的访问定位

JVM&#xff08;三&#xff09;——对象的访问定位创建完对象&#xff0c;到了使用对象的时候&#xff0c;通常声明一个同类型的引用指向该类型的对象&#xff0c;由这个引用来操作对象的字段、方法等。 Object obj new Object();复制代码我们的Java程序需要通过栈上的 refere…

html5滑动删除置顶,html5向左滑动删除特效

html5向左滑动删除特效* {padding: 0;margin: 0;list-style: none;}header {background: #f7483b;border-bottom: 1px solid #ccc}header h2 {text-align: center;line-height: 54px;font-size: 16px;color: #fff}.list-ul {overflow: hidden}.list-li {line-height: 60px;bord…

Java Double类hashCode()方法及示例

双类hashCode()方法 (Double class hashCode() method) hashCode() method is available in java.lang package. hashCode()方法在java.lang包中可用。 hashCode() method is used to return hashcode of the Double-object. hashCode()方法用于返回Double对象的哈希码。 hashC…

Java DataOutputStream size()方法及示例

DataOutputStream类的size()方法 (DataOutputStream Class size() method) size() method is available in java.io package. size()方法在java.io包中可用。 size() method is used to return the size of this stream or in other words, we can say it returns the value of…

html怎样让列表向下移动,Html无序列表ul控件实现行上下移动.

new document // 创建一个ulvar ul document.createElement("ul");ul.id "oList";// 创建divvar div document.getElementById(mergeCase);// 把ul放置到div中div.appendChild(ul);// 遍历所有的li条目function trace(){var strTest "";for …

创建laravel项目

下载项目到本地 git clone https://github.com/251068550/LaraBlog.gitcompoer安装 cd LaraBlog composer install如果composer install安装很慢&#xff0c;推荐安装国内镜像 执行 composer config -g repo.packagist composer https://packagist.phpcomposer.com 配置.env文件…

Java ArrayList removeRange()方法与示例

ArrayList类removeRange()方法 (ArrayList Class removeRange() method) removeRange() method is available in java.util package. removeRange()方法在java.util包中可用。 removeRange() method is used to remove the elements whose range is between st_in(start index)…

Spring注释事务失效及解决办法

如果带上事务&#xff0c;那么用annotation方式的事务注解和bean配置&#xff0c;事务会失效&#xff0c;要将service bean配置到xml文件中才行 在主容器中&#xff08;applicationContext.xml&#xff09;&#xff0c;将Controller的注解排除掉 <context:component-scan …

html5画分形图形,2.5 绘制透明图形 - HTML5 Canvas 实战

对于需要图形分层的应用&#xff0c;经常需要处理透明度。本节&#xff0c;我们将学习如何使用全局透明度设置图形的透明度。图2-5 绘制透明图形绘制步骤按照以下步骤&#xff0c;在一个不透明的矩形之上&#xff0c;绘制一个透明的圆&#xff1a;1. 定义2D画布上下文&#xff…

计算机网络子网划分_子网划分和超网| 计算机网络

计算机网络子网划分1)子网划分 (1) Subnetting) Subnetting is a concept of diving a block of addresses into sub-blocks of addresses. During the era of classful addressing (as it’s obscured now), subnetting was introduced. Say, an organization is granted a la…

html5录音功能代码,recorder.js 基于 HTML5 实现录音功能

recorder.js 基于 HTML5 实现录音功能2020-06-23 01:49:56recorder.jsmicrophone基于HTML5的录音功能&#xff0c;输出格式为mp3文件。前言完全依赖H5原生API所涉及的API&#xff1a;WebRTC、AudioContext、Worker、Video/Audio API、Blob、URL兼容性Chrome、FF、Edge、QQ、360…

data.frame类型数据如何将第一列值替换为行号

data.frame类型数据如何将第一列值替换为行号 row.names(data) <- data[, 1]data <- data[, -1]