public class test001 {
public static void main(String[] args) throws Exception {
String str2 = “测ABC试DEF”;
splitString(str2,6);
}
public static String splitString(String str,int len)throws Exception{
if (null==str){
System.out.println("The string is null");
}
int byteNum =0;
byte[] bt = str.getBytes();
byteNum = bt.length;
if (len>byteNum){
len = byteNum;
}
if (bt[len]<0){
str = new String(bt,0,--len);
System.out.println(str);
}else{
str = new String(bt,0,len);
System.out.println(str);
}
return str;
}
}