如何与其他类 java android

问题描述 投票:0回答:0

通过 java/android 学习曲线工作...我创建了一个文本文件,我想在其中保留我的应用程序的所有设置。从文件中读取这些工作正常。现在,我怎么能简单地在其他类中使用这三个值呢?提前致谢!

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();
    }
}
java android configuration-files
© www.soinside.com 2019 - 2024. All rights reserved.