Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

byte to string android

So I'm using files to save some scores of my program but the problem is that I don't can't just print them. I tryed several things but I don't find the right one the is my code:

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();
    }
like image 663
stevedc Avatar asked Dec 06 '22 14:12

stevedc


1 Answers

You can convert Byte array to string by creating new string object.

byte[] b = new byte[1];
fos.read(b);
fos.close();
String message = new String(b);
like image 117
Animesh Sinha Avatar answered Dec 22 '22 09:12

Animesh Sinha