日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

Java InputStreamReader getEncoding()方法及示例

發(fā)布時(shí)間:2023/12/1 java 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java InputStreamReader getEncoding()方法及示例 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

InputStreamReader類的getEncoding()方法 (InputStreamReader Class getEncoding() method)

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

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

  • getEncoding() method is used to get the encoding name avail for this InputStreamReader stream and it returns a historical encoding name when it exists otherwise it returns canonical encoding name.

    getEncoding()方法用于獲取此InputStreamReader流的編碼名稱,如果存在,則返回歷史編碼名稱,否則返回規(guī)范編碼名稱。

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

    getEncoding()方法是一個(gè)非靜態(tài)方法,只能通過(guò)類對(duì)象訪問(wèn),如果嘗試使用類名稱訪問(wèn)該方法,則會(huì)收到錯(cuò)誤消息。

  • getEncoding() method does not throw an exception at the time of getting encoding.

    getEncoding()方法在獲取編碼時(shí)不會(huì)引發(fā)異常。

Syntax:

句法:

public String getEncoding();

Parameter(s):

參數(shù):

  • It does not accept any parameter.

    它不接受任何參數(shù)。

Return value:

返回值:

The return type of the method is String, it gets historical character encoding name when exists otherwise it returns canonical encoding name or it may return null when this stream has been closed.

該方法的返回類型為String ,如果存在則獲取歷史字符編碼名稱,否則返回規(guī)范編碼名稱,或者在關(guān)閉此流時(shí)返回null。

Example:

例:

// Java program to demonstrate the example // of String getEncoding() method // of InputStreamReaderimport java.io.*;public class Demo1 {public static void main(String[] args) throws Exception {InputStream is_stm = null;InputStreamReader isr_stm = null;int val = 0;try {// Instantiates FileInputStream and InputStreamReader is_stm = new FileInputStream("D:\\includehelp.txt");isr_stm = new InputStreamReader(is_stm);// By using getEncoding() method is to // get the character encoding used by the // stream isr_stmString encoding = isr_stm.getEncoding();System.out.println("isr_stm.getEncoding(): " + encoding);} catch (Exception ex) {System.out.println(ex.toString());} finally {// with the help of this block is to// free all necessary resources linked// with the streamif (is_stm != null) {is_stm.close();if (isr_stm != null) {isr_stm.close();}}}} }

Output

輸出量

isr_stm.getEncoding(): Cp1252

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

總結(jié)

以上是生活随笔為你收集整理的Java InputStreamReader getEncoding()方法及示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。