2

我有一个问题,因为我想将按钮位置(MainMenu.Menu_Options)保存到属性文件中并读取它。我怎样才能做到这一点?我知道我可以使用 getLocation() 但我需要将其转换为字符串。代码:

try{
        options.setProperty("firstbackcolor", firstbackgroundColor.toString());
        options.setProperty("secondbackcolor", secondbackgroundColor.toString());
        options.setProperty("firsttext", firsttextColor.toString());
        options.setProperty("secondtext", secondtextColor.toString());
        options.setProperty("Slot_Options", MainMenu.Menu_Options.getLocation());


        options.store(new FileOutputStream(SupremeDataPath),null);
    }catch(Exception e){}

任何人?

4

1 回答 1

1

如果要读取用于存储位置的属性文件,可以执行以下操作:

     // read from properties file
    Properties properties = new Properties();

    try {
        File file = new File("path here");
        properties.load(new FileInputStream(file));
    } catch (IOException e) {
        e.printStackTrace();
    }

    String location = (String) properties.get("key.to.location");

    // write to properties file
    properties.setProperty("key.new.location", "new location");
    properties.store(new FileOutputStream(file), "comment");
于 2013-09-10T17:46:19.847 回答