Java RandomAccessFile writeBytes()方法與示例

RandomAccessFile類writeBytes()方法 (RandomAccessFile Class writeBytes() method)

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

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

  • writeBytes() method is used to write the sequence of bytes (i.e. string) to the file. Every character exists in the string is written out in a sequence by skipping its higher 8 bits

    writeBytes()方法用于將字節序列(即字符串)寫入文件。 字符串中存在的每個字符通過跳過其高8位而按順序寫出

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

    writeBytes()方法是一個非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • writeBytes() method may throw an exception at the time of writing bytes.

    writeBytes()方法在寫入字節時可能會引發異常。

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

    IOException :在執行輸入/輸出操作時,此異常可能會引發異常。

Syntax:

句法:

    public final void writeBytes(String str);

Parameter(s):

參數:

  • String str – represents the string to write.

    字符串str –表示要寫入的字符串。

Return value:

返回值:

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

此方法的返回類型為void ,不返回任何內容。

Example:

例:

// Java program to demonstrate the example 
// of void writeBytes(String str) method of
// RandomAccessFile
import java.io.*;
class RAFWriteBytes {
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 writeBytes() method is to 
// write sequence of bytes i.e. string
// at a time to the file
ra_f.writeBytes("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 readLine() method is to 
// read string from this file
System.out.println("ra_f.readLine(): " + ra_f.readLine());
// By using close() method isto
// close this stream ran_f
ra_f.close();
}
}

Output

輸出量

ra_f.readLine(): Welcome, in Java World!!!!!

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379657.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379657.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379657.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

linux內核設計與實現---下半部和推后執行的工作

下半部和推后執行的工作1 下半部為什么要用下半部下半部的環境內核定時器2 軟中斷軟中斷的實現軟中斷處理程序執行軟中斷使用軟中斷3 tasklettasklet的實現使用taskletksoftirqd4 工作隊列工作隊列的實現工作、工作隊列和工作者線程之間的關系使用工作隊列5 下半部機制的選擇6 …

Jquery對復選框的操作

<from> 你的愛好是?<br/> <input type"checkbox" name"items" value"籃球" />籃球 <input type"checkbox" name"items" value"乒乓球" />乒乓球 <input type"checkbox" na…

HttpServletRequest(request的一些API)

一、request的運行流程 首先&#xff0c;自己寫一個web工程&#xff0c;也就是建一個工程&#xff1b;當把該web工程發布到Tomcat服務器當中&#xff0c;可以讓外界訪問&#xff0c;這就成了一個web應用。 在客戶端輸入一個網站&#xff0c;是web應用資源的地址URL&#xff0c…

DCI:James O. Coplien和Trygve Reenskau提出的新架構方法

http://www.infoq.com/cn/news/2009/05/dci-coplien-reenskau 轉載于:https://www.cnblogs.com/yelinpalace/archive/2009/06/13/1502573.html

Java ObjectStreamField getOffset()方法與示例

ObjectStreamField類的getOffset()方法 (ObjectStreamField Class getOffset() method) getOffset() method is available in java.io package. getOffset()方法在java.io包中可用。 getOffset() method is used to get the offset of this ObjectStreamField field. getOffse…

Mac VSCode配置C語言環境(可以調試)

Mac VSCode配置C語言環境c_cpp_properties.jsontasks.jsonlaunch.json新建一個文件夾&#xff0c;用vscode&#xff0c;然后再新建一個test.c文件。 #include <stdio.h>int main(void) {int a1,b1;int cab;printf("%d\n",c);return 0; }這篇文章說怎么配置c_c…

XmlPullParserException

今天在android的開發中約到一個問題 使用Ksoap2 訪問 WebService 拋出 XmlPullParserException 異常。 在網上淘了一下這個問題 http://www.eoeandroid.com/thread-70527-1-1.html 不能解決我的問題&#xff0c;求解轉載于:https://www.cnblogs.com/pengqinping/archive/2012/0…

vShpere Client在win 7 RC下和2008下 無法正常連接esx主機之解決辦法

vShpere Client在win 7 RC下和2008下 無法正常連接esx主機之解決辦法 在win7下和2008下打開client后連接esx主機會出現2個錯誤提示, 第一個是 第二個是 然后就連接失敗了,開始以為是CC的esx主機安裝有問題,后來找了找,借助了強大google工具,終于找到解決辦法.解決辦法如下: 1.從…

tooctalstring_Java Integer類toOctalString()方法的示例

tooctalstring整數類toOctalString()方法 (Integer class toOctalString() method) toOctalString() method is available in java.lang package. toOctalString()方法在java.lang包中可用。 toOctalString() method is used to represent an octal string of the given parame…

localhost與127.0.0.1之間的關系更改

其實localhost的默認IP地址為127.0.0.1&#xff0c;因為這是一種映射關系。 更改步驟如下&#xff1a; C:\Windows\System32\drivers\etc 下的hosts 打開hosts可以看到 更改即可

基于Hash表的排序--C語言

我們知道&#xff0c;C語言里面是沒有hash表的&#xff0c;但是我們可以用一個結構體表示&#xff0c;對結構體排序&#xff0c;我們可以用qsort排序。 下面我們用一個LeedCode上面的一道題目講解。 347. 前 K 個高頻元素 這個題目是讓我們求解前k個高頻元素&#xff0c;求解思…

ORACLE10g R2及PATH官方下載地址

ORACLE10g R2及PATH官方下載地址 Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for Microsoft Windows (32-bit)http://download.oracle.com/otn/nt/oracle10g/10201/10201_database_win32.zip http://download.oracle.com/otn/nt/oracle10g/102…

[網摘]Javascript中最常用的55個經典技巧

1. οncοntextmenu"window.event.returnValuefalse" 將徹底屏蔽鼠標右鍵<table border οncοntextmenureturn(false)><td>no</table> 可用于Table 2. <body onselectstart"return false"> 取消選取、防止復制 3. οnpaste"…

Java集合unmodifiableMap()方法及示例

集合類unmodifiableMap()方法 (Collections Class unmodifiableMap() method) unmodifiableMap() method is available in java.util package. unmodifiableMap()方法在java.util包中可用。 unmodifiableMap() method is used to get a non-modifiable view of the given Map (…

Linux內核設計與實現---內核同步方法

內核同步方法1 原子操作原子整數操作原子性與順序性的比較原子位操作2 自旋鎖自旋鎖是不可遞歸的其他針對自旋鎖的操作自旋鎖和下半部3 讀-寫自旋鎖4 信號量創建和初始化信號量使用信號量5 讀-寫信號量6 自旋鎖和信號量7 完成變量8 互斥鎖互斥鎖API9 禁止搶占10 順序和屏障1 原…

單擊瀏覽器右上角的X彈出提示窗口

單擊瀏覽器右上角的X彈出提示窗口&#xff0c;簡單實現。 <script language"javascript">window.onunload function () { if (event.clientY < 0 && event.clientX> document.body.scrollWidth) { //event.returnValue …

Java DataOutputStream writeChars()方法及示例

DataOutputStream類writeChars()方法 (DataOutputStream Class writeChars() method) writeChars() method is available in java.io package. writeChars()方法在java.io包中可用。 writeChars() method is used to write the given string as a sequence of characters to th…

對c#拆裝箱的性能分析(泛型)

c#中&#xff0c;數據類型主要分為2種&#xff0c;分別為值類型和引用類型。把值類型轉換為引用類型稱為裝箱&#xff0c;把引用類型轉換為值類型稱為拆箱。在c#中&#xff0c;值類型是在堆棧上分配內存的&#xff0c;而引用類型是在堆上分配內存的。裝箱的時候&#xff0c;CLR…

UNIX環境高級編程---進程間通信總結

進程間通信1 管道匿名管道命名管道2 消息隊列3 信號量POSIX信號量有名信號量無名信號量有名信號量和無名信號量的公共操作4 共享內存5 信號相關函數6 套接字針對 TCP 協議通信的 socket 編程模型針對 UDP 協議通信的 socket 編程模型針對本地進程間通信的 socket 編程模型總結L…

C語言一個小小的問題引起的對指針的探究。。。

C語言一個小小的問題引起的對指針的探究。。。 廢話不多說。下面是這個大家認識的一個及其簡單的程序&#xff1a; 1 #include <stdio.h>2 void A(int a[])3 {4 printf("%d/t", sizeof(a));5 }6 int main()7 {8 int a[512];9 int *p; 10 …