---
title: "String(byte[] bytes, String charsetName) "
author: "瓊湳居士"
date: "2015-05-12T10:59:00Z"
tags: []
categories: ["Web前端"]
slug: "string-byte-bytes-string-charsetname"
draft: false
lastmod: "2015-05-12T10:59:00Z"
id: 2210429
url: "https://3138401460.iteye.com/blog/2210429"
---

```
String str = new String("时之沙");
		byte bytes[] = str.getBytes("GBK");
		byte byte2[] = str.getBytes("ISO-8859-1");
		String str_gbk = new String(bytes, "GBK");
		System.out.println("str_gbk:" + str_gbk);
		String str_utf8 = new String(bytes, "UTF-8");
		System.out.println("str_utf8:" + str_utf8);
		String str_iso8859 = new String(bytes, "ISO-8859-1");
		System.out.println("str_iso8859" + str_iso8859);
		String byte2_gbk = new String(byte2, "GBK");
		System.out.println("byte2_gbk:" + byte2_gbk);
```

 输出结果:

str\_gbk:时之沙  
str\_utf8:ʱ֮ɳ  
str\_iso8859Ê±Ö®É³  
byte2\_gbk:???