InputStreamReader的构造方法
InputStreamReader(InputStream in)创建一个使用默认字符集的 InputStreamReader。
请问这里的默认的字符集是什么意思?
这样的一段代码: String str = getContion(keyXm, xm, keyZjhm, zjhm);
String path = ServletActionContext.getServletContext().getRealPath("");
Process p = Runtime.getRuntime().exec("java -Dfile.encoding=GBK -jar " + path + "/adapter.jar " + type + " " + str);
InputStream is = p.getInputStream();
InputStreamReader reader = new InputStreamReader(
is, "GBK"); StringBuffer buffer = new StringBuffer();
char[] buf = new char[64];
int count = 0;
try {
while ((count = reader.read(buf)) != -1)
buffer.append(buf, 0, count);
}
finally {
reader.close();
}
String result = buffer.toString(); 为什么要指定InputStreamReader reader = new InputStreamReader(is, "GBK");
字符集为GBK,在测试中,不指定字符集得到的result 出现了部分的乱码现象(有中文)字符集
InputStreamReader(InputStream in)创建一个使用默认字符集的 InputStreamReader。
请问这里的默认的字符集是什么意思?
这样的一段代码: String str = getContion(keyXm, xm, keyZjhm, zjhm);
String path = ServletActionContext.getServletContext().getRealPath("");
Process p = Runtime.getRuntime().exec("java -Dfile.encoding=GBK -jar " + path + "/adapter.jar " + type + " " + str);
InputStream is = p.getInputStream();
InputStreamReader reader = new InputStreamReader(
is, "GBK"); StringBuffer buffer = new StringBuffer();
char[] buf = new char[64];
int count = 0;
try {
while ((count = reader.read(buf)) != -1)
buffer.append(buf, 0, count);
}
finally {
reader.close();
}
String result = buffer.toString(); 为什么要指定InputStreamReader reader = new InputStreamReader(is, "GBK");
字符集为GBK,在测试中,不指定字符集得到的result 出现了部分的乱码现象(有中文)字符集
InputStream is = p.getInputStream();
InputStreamReader reader = new InputStreamReader(is, "GBK");
(is//是把字节流InputStream is转为字符流InputStreamReader “gbk”是指定用GBK格式读它)
InputStreamReader(InputStream in)创建一个使用默认字符集的 InputStreamReader
这个默认的字符集与操作系统有关吗?如果与操作系统有关,那么怎么查看windows和linux的字符集
public class CharserDemo01
{
public static void main(String[] args)
{
System.out.println("本机使用的字符集:" + System.getProperty("file.encoding"));
}
}
当我们保存数据到磁盘的时候,如果没有指定字符集,那么操作系统将按照默认字符集保存,当然也可以指定字符集(例如Edit plus保存文件的时候,可以指定编码,Eclipse也可以指定文本编码)保存;当操作系统从磁盘上读取数据的时候,如果读取的文件没有指定字符集,那么将按照操作系统的默认字符集来读取;当然,对于指定了字符集的文件,那么操作系统将按照指定的字符集读取。
windows操作系统和linux操作系统的默认字符集可以改变吗?如果可以改变,我想一般不会轻易改变吧
这个表述好像有误,保存文件到磁盘是应用程序(记事本)的工作,而不是操作系统,读取文件也是一样。操作系统在其中的角色我觉得好像是
1. 提供默认的(和非默认的)字符集(包括编码表)给应用程序,以用于编码和解码
还有个问题:磁盘上的文件内容中是否保存了文件的字符集信息?