为什么以UTF8格式读取UTF8格式文件,写入输出流后还是乱码

用UTF8编码读入一个utf8的文件,结果写入输出流的时候还是乱码?这是怎么回事?
InputStream ist = LaucherTest.class.getResourceAsStream("/Book1.csv");

InputStreamReader reader = new InputStreamReader(ist,"UTF-8");
ByteArrayOutputStream str= new ByteArrayOutputStream();
int ch;
while((ch=reader.read())!=-1){
str.write(ch);
}
查看str内容,结果还是乱码 :!:

nputStreamReader reader = new InputStreamReader(ist,"UTF-8");
ByteArrayOutputStream str= new ByteArrayOutputStream();
int ch;
while((ch=reader.read())!=-1){
str.write(ch);
}

Reader读/Writer写 字符
InputStream读/OutputStream写 字节
它们要配套使用

现在你混用了。把ByteArrayOutputStream改成OutputStreamWriter

InputStreamReader read() 是读取一个字符;
ByteArrayOutputStream write(int b) 将指定的字节写入此字节数组输出流。

[code="java"]
public synchronized void write(int b) {
int newcount = count + 1;
if (newcount > buf.length) {
byte newbuf[] = new byte[Math.max(buf.length << 1, newcount)];
System.arraycopy(buf, 0, newbuf, 0, count);
buf = newbuf;
}
buf[count] = (byte)b;//在这里转换为byte,只有一个字节,字符是两个字节
count = newcount;
}
[/code]

应该用Writer,比如CharArrayWriter、 PrintWriter等。

.java 和项目encoding 转为uft-8

你是怎么查看str里的内容的?你能确定查看的方式是UTF-8编码的吗?