在如下五种字符格式见进行转换
"ISO-8859-1"
"UTF-8"
"UTF-16BE"
"UTF-16LE"
"US-ASCII
public static String transform(String src,String srcEn,String dstEn)
{
String result = "";
try
{
ByteArrayInputStream inputStream = new ByteArrayInputStream(src.getBytes());
InputStreamReader inputStreamReader = new InputStreamReader(inputStream,srcEn);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream,dstEn);
int ch;
// 以字元方式显示档案内容
while((ch = inputStreamReader.read()) != -1) {
System.out.print((char)ch);
outputStreamWriter.write(ch);
}
System.out.println();
inputStreamReader.close();
outputStreamWriter.close();
byte rc[] = outputStream.toByteArray();
result = new String(rc);
}
catch(ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}
return result;
}