Java-io-datainputstream-readutf-in

提供:Dev Guides
移動先:案内検索

Java.io.DataInputStream.readUTF()メソッド

説明

  • java.io.DataInputStream.readUTF(DataInput in)*メソッドは、変更されたUTF-8形式を使用してエンコードされた文字列を読み取ります。

宣言

以下は* java.io.DataInputStream.readUTF(DataInput in)*メソッドの宣言です-

public static final String readUTF(DataInput in)

パラメーター

NA

戻り値

このメソッドは、an = Unicode文字列を返します。

例外

  • EOFException
  • UTFDataFormatException
  • IOException -I/Oエラーが発生した場合。

次の例は、java.io.DataInputStream.readUTF(DataInput in)メソッドの使用方法を示しています。

package com.finddevguides;

import java.io.FileOutputStream;
import java.io.IOException;

public class FileOutputStreamAvailable extends FileOutputStream {

   public FileOutputStreamAvailable() throws Exception {
      super("C://test.txt");
   }

   public static void main(String[] args) throws IOException {
      FileOutputStreamAvailable fosa = null;

      try {
        //create new File input stream
         fosa = new FileOutputStreamAvailable();

        //read byte from file input stream
         fosa.finalize();

        //converts int to char
         System.out.println("Stream is closed successfully.");

      } catch(Exception ex) {
        //if any error occurs
         ex.printStackTrace();
      } finally {
        //releases all system resources from the streams
         if(fos!=null)
            fos.close();
      }
   }
}

テキストファイル* c:/test.txt*があり、次の内容があるとします。 このファイルは、サンプルプログラムの入力として使用されます-

ABCDE

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

Stream is closed successfully.