字节到字符串android

ste*_*edc 4 string android byte

所以我使用文件来保存我的程序的一些分数,但问题是我不能只打印它们.我尝试了几件事但我找不到合适的东西是我的代码:

try{
        String FILENAME = "FrogScoreFile";
        FileInputStream fos = openFileInput(FILENAME);
        byte[] b = new byte[1];
        fos.read(b);
        fos.close();
        String score= String b;
        game5HighScore.setText(b);
        }catch (java.io.FileNotFoundException e) {
        } catch (IOException e) {
                e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

Ani*_*nha 15

您可以Byte array通过创建new string对象转换为字符串.

byte[] b = new byte[1];
fos.read(b);
fos.close();
String message = new String(b);
Run Code Online (Sandbox Code Playgroud)