當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java DataOutputStream writeLong()用法及代碼示例

DataOutputStream類writeLong()方法

  • writeLong() 方法可在java.io包。
  • writeLong() 方法用於將給定的 long 值以 8 字節(即 64 位)的形式寫入基本 DataOutputStream,並且變量 counter 在成功執行時加 8。
  • writeLong() 方法是一個非靜態方法,它隻能通過類對象訪問,如果我們嘗試使用類名訪問方法,那麽我們將得到一個錯誤。
  • writeLong() 方法可能會在寫入 long 時拋出異常。
    IOException:在獲取任何輸入/輸出錯誤時可能會拋出此異常。

用法:

    public final void writeLong(long val);

參數:

  • long val– 表示要寫入數據輸出流的long值。

返回值:

該方法的返回類型是void,它什麽都不返回。

例:

// Java program to demonstrate the example 
// of void writeLong(long val) method 
// of DataOutputStream

public class GetSignersOfClass {
 public static void main(String[] args) throws Exception {
  // Creating an instance of String
  String str = new String();

  // It returns the Class object represented by the String class
  // object
  Class cl = str.getClass();

  // By using getSigners() method is to get the signers of the Class
  Object[] o = cl.getSigners();
  System.out.println(cl.getName() + " " + "Signers:" + o);
 }
}

輸出

java.lang.String Signers:null


相關用法


注:本文由純淨天空篩選整理自Preeti Jain大神的英文原創作品 Java DataOutputStream writeLong() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。