0

Working through java/android learning curve... I created a text file where I want to keep all the settings for my app. Reading these from the file is working OK. Now, how could I simply use these three values in other classes? Thanks in advance!

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    bind = ActivityHomeBinding.inflate(getLayoutInflater());
    setContentView(bind.getRoot());
    ReadConfigFile();
    initView();
}

public static void ReadConfigFile() {
    try (FileInputStream fis = new FileInputStream("/storage/emulated/0/Download/suivicourse.cfg")) {
        Properties prop = new Properties();
        prop.load(fis);
        String sc_url = prop.getProperty("database.url");
        String sc_user = prop.getProperty("database.username");
        String sc_pswd = prop.getProperty("database.password");
        System.out.println(sc_url);
        System.out.println(sc_user);
        System.out.println(sc_pswd);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
  • 1
    why text file instead of shared preferences? – Marcin Orlowski Apr 24 '23 at 16:44
  • Thank you @MarcinOrlowski. I added shared preferences and it works well. But is it possible to locate the preferences xml file in a folder that is easier to access, such as /storage/emulated/0/Download ? – Pierre Tremblay Apr 24 '23 at 22:45
  • You're free to post a link to a tutorial in a comment, though. And if the tutorial did help you solve the issue, you can quote the relevant parts, and explain what you changed. That makes for a good answer. – Andreas is moving to Codidact May 01 '23 at 02:59

0 Answers0