int total = 0; int index = 0; for (int i = 0; i < str.length(); ) { String tmp = str.substring(i, ++i); total += tmp.getBytes(encodeing).length; index ++; if (total >= length) { break; } } //取较小的 index = (index > str.length()) ? str.length() : index; return str.substring(0, index); } }