1 需求
2 接口
Class InputStreamReader
java.lang.Object
java.io.Reader
java.io.InputStreamReader
- Constructor Detail
- public InputStreamReader(InputStream in)
- public InputStreamReader(InputStream in, String charsetName) throws UnsupportedEncodingException
- public InputStreamReader(InputStream in, Charset cs)
- public InputStreamReader(InputStream in, CharsetDecoder dec)
- Method Detail
- public String getEncoding()
- public int read() throws IOException
- public int read(char[] cbuf, int offset, int length) throws IOException
- public boolean ready() throws IOException
- public void close() throws IOException
Class OutputStreamWriter
java.lang.Object
java.io.Writer
java.io.OutputStreamWriter
- Constructor Detail
- public OutputStreamWriter(OutputStream out, String charsetName) throws UnsupportedEncodingException
- public OutputStreamWriter(OutputStream out)
- public OutputStreamWriter(OutputStream out, Charset cs)
- public OutputStreamWriter(OutputStream out, CharsetEncoder enc)
- Method Detail
- public String getEncoding()
- public void write(int c) throws IOException
- public void write(char[] cbuf, int off, int len) throws IOException
- public void write(String str, int off, int len) throws IOException
- public void flush() throws IOException
- public void close() throws IOException
3 示例代码
示例代码:判断cmd命令行编码格式:GBK
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) throws IOException {
InputStreamReader reader = new InputStreamReader(Runtime.getRuntime().exec("cmd /c dir").getInputStream());
System.out.println(reader.getEncoding());
}
}
4 参考资料



