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流的編碼名稱,如果存在,則返回歷史編碼名稱,否則返回規范編碼名稱。

  • 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()方法是一個非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

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

    getEncoding()方法在獲取編碼時不會引發異常。

Syntax:

句法:

    public String getEncoding();

Parameter(s):

參數:

  • It does not accept any parameter.

    它不接受任何參數。

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 ,如果存在則獲取歷史字符編碼名稱,否則返回規范編碼名稱,或者在關閉此流時返回null。

Example:

例:

// Java program to demonstrate the example 
// of String getEncoding() method
// of InputStreamReader
import 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_stm
String 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 stream
if (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

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

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

相關文章

python安全攻防---爬蟲基礎---BeautifulSoup解析

0x01 基礎 使用bs4首先要安裝,安裝后導入 import bs4bs對象有兩個方法,一個是find,另一個是find_all find(標簽名,屬性值):只返回一個,返回也是bs對象,可以繼續用find…

DataRabbit 3.1發布,完全支持SqlServer2005/2008

增加了對SqlServer2005/2008的新的數據類型的支持,如uniqueidentifier、time、sql_variant等。另外,EntityCreator也一起更新--不再強迫為Entity生成ToString()方法,使用者可以主動選擇是否要生成。 DataRabbit 3.1 下…

Java——Socket通信原理

* Socket通信原理圖解* A:Socket(中文翻譯為:電源插座)套接字概述* 網絡上具有唯一標識的IP地址和端口號組合在一起才能構成唯一能識別的標識套接字* 通信的兩端都有Socket(兩端都是電源插座,中間是啥?不就是電線啦,電…

asp.net鏈接mysql數據庫------------【個人收集】

在web.config文件中添加如下樣式的數據庫鏈接字符串&#xff1a; <add name"dbconnection" connectionString"DataBasedatabasename;Server127.0.0.1;Uid用戶名;Pwd密碼;character setgbk;" providerName"MySql.Data.MySqlClient"/></c…

sql2005 遠程連接

SQL Server 2005 不允許遠程連接解決方法轉載于:https://www.cnblogs.com/lcq135/archive/2008/11/06/1328380.html

Java GregorianCalendar computeTime()方法與示例

GregorianCalendar類computeTime()方法 (GregorianCalendar Class computeTime() method) computeTime() method is available in java.util package. java.util包中提供了computeTime()方法 。 computeTime() method is used to compute the calendar fields to the calendar …

python安全攻防---scapy基礎---計算機網絡各層協議

網絡層次劃分 比較常用的是TCP/IP五層協議。 0x01應用層 應用層是網絡應用程序以及它們的應用層協議存留的地方。應用層協議和應用程序直接掛鉤 DHCP(Dynamic Host Configuration Protocol)動態主機分配協議&#xff0c;使用 UDP 協議工作&#xff0c;主要有兩個用途&#xf…

一點心得(0)

1, 在C中&#xff0c;如果棧里的空間不足的話&#xff0c;要考慮用new命令在堆上動態生成數據&#xff0c;比如說保存所有無符號整數型的bitset&#xff0c;得用bitset<UINT_MAX1>* bs new bitset<UINT_MAX1>;來聲明定義&#xff0c;最后別忘了delete掉。 2, make…

Java——UPD輸出及優化再優化

* UPD傳輸不區分客戶端跟服務端&#xff0c;* 這里用Send和Receive這兩個方法決定誰發誰收 * 1.發送Send * 創建DatagramSocket,隨機端口號* 創建DatagramPacket,指定數據、長度、地址、端口* 創建DatagramSocket發送DatagramPacket* 關閉DatagramSocket 代碼如下&…

FLEX:圖形制作皮膚vs編程制作皮膚

Styles&#xff08;樣式&#xff09;提供了一個可以自定義flex外觀的層.可以圖形制作皮膚&#xff0c;也可以編程實現. &#xff08;小小菜鳥翻譯&#xff09; 圖形制作皮膚的 優點是 很容易實現&#xff0c;通過位圖&#xff0c;矢量圖&#xff0c;swf。 缺點是功能有限。…

Java文件類boolean canExecute()方法(帶示例)

文件類boolean canExecute() (File Class boolean canExecute()) This method is available in package java.io.File.canExecute(). 軟件包java.io.File.canExecute()中提供了此方法。 This method is used to execute the file and the file is represented by the abstract …

python安全攻防---scapy使用

導入scapy包 from scapy.all import *構造包 a Ether()/IP(dst114.114.114.114)/TCP(dport80)/應用層數據我們如果記不得每個包的選項使&#xff0c;可以使用show()來查看 print(a.show())發送包 sr(IP(dst‘192.168.1.0/24’)/TCP(dport(1,65535)), timeout2) &#xff1…

唉!

學習到后面時&#xff0c;再返回看了一下前面學過的&#xff0c;發現以前學過&#xff0c;看不懂的東西現在能看懂了…… &#xff01;不過 為什么在剛學時就是不懂&#xff0c;這樣 不就老是慢一拍嗎&#xff1f;唉&#xff01;&#xff01;轉載于:https://www.cnblogs.com/ni…

Java—— TCP協議(相關代碼實現以及相關優化)

代碼運行的時候先運行服務端&#xff0c;然后在運行客戶端 * TCP協議&#xff1a;* 1&#xff0c;客戶端* 創建Socket連接服務器(指定IP地址&#xff0c;端口號)通過IP地址找到對應的服務器* 調用Socket的getInputStream()和getOutputStream()方法獲取和服務器端相連…

什么是adsense 想通過廣告掙錢的看過來

Adsense的含義Google AdSense是由Google公司推出的針對網站主&#xff08;簡稱發布商&#xff09;的一個互聯網廣告服務。AdSense是個合成詞。其中ad是“廣告”之意&#xff0c;sense是“感知”之意&#xff0c;綜合起來的意思就是相關廣告。Google通過程序來分析網站的內容&am…

Java GregorianCalendar getTimeZone()方法與示例

GregorianCalendar類的getTimeZone()方法 (GregorianCalendar Class getTimeZone() method) getTimeZone() method is available in java.util package. getTimeZone()方法在java.util包中可用。 getTimeZone() method is used to return the time zone for this GregorianCale…

python安全攻防---信息收集---ICMP主機探測 以及optionparser的使用

0x01 基礎概念 ICMP&#xff08;Internet control Message Protocal&#xff09;Internet報文協議&#xff0c;是TCP/IP的一種子協議&#xff0c;屬于網絡層協議&#xff0c;其目的是用于在IP主機、路由器之間傳遞控制信息 0x02 程序 程序 # -*- coding:utf-8 -*- from sca…

PHP文件系統-文件下載

一、網頁請求和響應的過程 請求&#xff1a; 1. HTTP 1.1 協議 版本 2. 頭信息&#xff0c;請求的ip&#xff0c;其他 3. 你請求的表單信息, 你提交給服務器的信息 http://localhost/one.php?aabbb&cccdd 響應&#xff1a; 1. 狀態 200 ok 404 頁面沒找到 2. 響應頭信息&a…

Java——網絡編程練習

練習一(黑馬程序員面試題)&#xff1a;客戶端向服務器寫字符串(鍵盤錄入)&#xff0c;服務器(多線程)將字符串反轉后寫回&#xff0c;客戶端再次讀取到的是反轉后的字符串 相關代碼如下&#xff1a; package com.wsq.test;import java.io.BufferedReader; import java.io.Buf…

第一章 基礎知識---1.4Crack小實驗--復現

0x01 程序及其編譯環境 程序如下&#xff0c;功能&#xff1a;我們必須輸入正確的密碼1234567才能得到密碼驗證的確認&#xff0c;跳出循環。否則程序提示密碼錯誤再次輸入。 #include <stdio.h>#define PASSWORD "1234567"int verify_password(char* passwo…