I'm trying to save some properties and print them out, but it doesn't work for some reason. Here's the code. My intention is to make a file that contains passwords and usernames, as pairs. And then later on I'm going to iterate through them. Is there an easier/better way to do this?
public void createUser(){
FileOutputStream fileOutputStream;
try{
fileOutputStream = context.openFileOutput("Testfile", context.MODE_PRIVATE);
properties.setProperty("username", "password");
properties.store(fileOutputStream, "User created");
fileOutputStream.close();
} catch(IOException e) {
Toast.makeText(context, "Error create", Toast.LENGTH_LONG).show();
}
And then I'm trying to print them out:
public void printUser( TextView textView){
File infoFile = new File(context.getFilesDir(), "TestFile");
BufferedReader br;
try{
br = new BufferedReader(new java.io.FileReader(infoFile));
properties.load(br);
textView.setText(properties.getProperty("username"));
} catch(IOException e) {
Toast.makeText(context, "Error printing users", Toast.LENGTH_LONG).show();
}
}
But nothing happens. I did basically the same in eclipse with JSwing and it worked well there.