0

I'm trying to save some data to A file in android, I'm using herefor the internal storage of the android system. I looked it up on the developers guide of android and I came to this.

String FILENAME = "LangFile"; String data ="NL"; FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); fos.write(data.getBytes()); fos.close(); 

This is how I save it to the file.

String FILENAME = "LangFile"; String languege = "lang"; FileInputStream fos = openFileInput(FILENAME); fos.read(languege.getBytes()); fos.close(); if(languege=="NL"){ newgame.setText(R.string.dutchgames); stats.setText(R.string.duthstats); } 

This is how I read from the same file, but if I run it it just gives an empty button?

3 Answers 3

1

You can't compare strings using ==, in fact you need to use either equals or equalsIgnoreCase methods. You also need to tweak your reading logic a little. Change your code as below:

FileInputStream fos = openFileInput(FILENAME); byte[] b = new byte[2]; //since lang-prefix should have at least length 2 fos.read(b); fos.close(); if(new String(b).equalsIgnoreCase("NZ")){ newgame.setText(R.string.dutchgames); stats.setText(R.string.duthstats); } 
Sign up to request clarification or add additional context in comments.

2 Comments

I tryed it on that way but it won't work still only the empty buttons
Your file reading logic is suspicious to me. Check my updated answer
0

did you add the permission to write the internal storage?

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

in your manifest.xml file

2 Comments

Where do I place this line in the manifest between the aplication or just above this. And is it the same for the internal storage?
It just stays the same, only empthy buttons
0
if(languege=="NL"){ newgame.setText(R.string.dutchgames); stats.setText(R.string.duthstats); } 

if condition is blocking from reading bytes from file. As == matches object references not their contents.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.