Java InputStreamReader getEncoding()方法及示例
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()方法是一個非靜態(tài)方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
getEncoding() method does not throw an exception at the time of getting encoding.
getEncoding()方法在獲取編碼時不會引發(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ī)范編碼名稱,或者在關閉此流時返回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
總結
以上是生活随笔為你收集整理的Java InputStreamReader getEncoding()方法及示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 夏至未至剧情介绍
- 下一篇: 杭州治疗卵巢功能减退最好的医院推荐