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

Java InputStreamReader getEncoding()方法及示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  3. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  4. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  5. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  6. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  7. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

  8. java arraylist.add(),Java ArrayList add()方法与示例

    ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...

  9. java rollback用法,Java Connection rollBack()方法与示例

    回滚操作将撤消当前事务所做的所有更改,即,如果调用Connection接口的rollBack()方法,则所有修改都将还原到最后一次提交. 您还可以通过将所需的Savepoint对象作为参数传递给此方法 ...

最新文章

  1. 卷积神经网络是如何实现不变性特征提取的
  2. Windows Azure Marketplace入门教学-利用TabLeau Public构建可视化DataMarket应用
  3. 《Spark大数据分析实战》——1.4节弹性分布式数据集
  4. Qt程序运行提示“it could not find or load the QT platform plugin “windows””
  5. python学习之-- redis模块管道/订阅发布
  6. 对你的的应用程序进行Debug
  7. 用于RIA的JavaFX 2与HTML5
  8. 论文阅读课3-GraphRel: Modeling Text as Relational Graphs for(实体关系联合抽取,重叠关系,关系之间的关系,自动提取特征)
  9. 为ASP.NET MVC应用添加自定义路由
  10. opencv 霍夫变换检测直线和圆
  11. 【转载】动态载入DLL所需要的三个函数详解(LoadLibrary,GetProcAddress,FreeLibrary)...
  12. 工程实践,淘宝直播高画质低延时技术探索
  13. php 读写局域网文件,PHP访问局域网共享文件
  14. 当今主流浏览器内核简介
  15. robots.txt文件示例
  16. 利用ECharts实现数据的左右移动
  17. 加工奶制品的生产计划
  18. 教你文件批量重命名技巧,彻底告别手工改名的繁琐
  19. About云双11两大福利:送书【9本】|送1T资源
  20. Chapter 2 (Matrix Algebra): The leontief input-output model (列昂惕夫投入产出模型)

热门文章

  1. linux iso合并,把RedHat Linux 5.0的CD ISO合并成DVD的脚本
  2. linux备份日志文件脚本,Linux篇:Shell脚本实现Gitlab双备份
  3. java填充二维数组_Java用Arrays.fill()初始化二维数组的实现
  4. 用了fastapi还需要nginx_nginx 与 fastdfs 的配置过程,已经越过了许多坑,我跪着进入了欢迎页面。。。...
  5. css布局:块级元素的居中
  6. scss-@for 指令
  7. border,padding,margin盒模型理解
  8. POJ 2236 - Wireless Network ( 并查集 )
  9. 需加装饰——装饰模式
  10. ASP.NET 泛型类型 Dictionary操作