---
title: "字节数组转字符串"
author: "softkf"
date: "2014-08-07T10:44:03Z"
tags: []
categories: ["移动开发"]
slug: "untitled"
draft: false
lastmod: "2014-08-07T10:44:03Z"
id: 2101228
url: "https://aijerry.iteye.com/blog/2101228"
---

```
public String byteTOString(byte[] src) {
	int idx = 0;
	for (idx = 0; idx < src.length; idx++) {
		if (src[idx] == (byte) 0) {
			break;
		}
	}
	try {
		return new String(src, 0, idx, "UTF-8");
	} catch (Exception e) {
		e.printStackTrace();
		return new String(src, 0, idx);
	}
}
```