// From http://code.calum.org/ int usernameLength = dataInputStread.readByte(); byte[] usernametmp = new byte[usernameLength]; for ( int i = 0 ; i < usernameLength ; i++ ){ usernametmp[i] = dis.readByte(); } String username = new String(usernametmp);