属性中的Java按钮位置

时间:2013-09-10 17:34:03

标签: java properties

我遇到了问题'因为我想将按钮位置(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){}

1 个答案:

答案 0 :(得分: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");
相关问题