public class BOMInputStream extends InputStream
getCharset()方法调用后会得到BOM头的编码,且会去除BOM头
String enc = "UTF-8"; // or NULL to use systemdefault
FileInputStream fis = new FileInputStream(file);
BOMInputStream uin = new BOMInputStream(fis, enc);
enc = uin.getCharset(); // check and skip possible BOM bytes
| Constructor and Description |
|---|
BOMInputStream(InputStream in)
构造
|
BOMInputStream(InputStream in,
String defaultCharset)
构造
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
String |
getCharset()
获取BOM头中的编码
|
String |
getDefaultCharset()
获取默认编码
|
protected void |
init()
Read-ahead four bytes and check for BOM marks.
|
int |
read() |
available, mark, markSupported, read, read, reset, skippublic BOMInputStream(InputStream in)
in - 流public BOMInputStream(InputStream in, String defaultCharset)
in - 流defaultCharset - 默认编码public String getDefaultCharset()
public String getCharset()
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionpublic int read()
throws IOException
read in class InputStreamIOExceptionprotected void init()
throws IOException
IOException - 读取引起的异常Copyright © 2025. All rights reserved.