2014-08-28 92 views
2

只是想知道,我认为它可能是,我只是在错误的方面 - 如果有一种方法来比较一个用户在一个属性文件中提出的东西和看看它是否匹配? (GitCommands是我的道具文件)比较用户输入到属性文件中的Java

而且,这里使用与

JButton btnSearch = new JButton("Search"); 
    btnSearch.addActionListener(new ActionListener() { 
     public void actionPerformed(ActionEvent e) { 
      //find selected command 

      //obtain text from field 
      String key_name = textFieldSearch.getText(); 
      FindSelectedKey(); 

这里寻找我的按钮是

public void FindSelectedKey() 
{ 
    if(textFieldSearch != null) 
    { 

    textFieldSearch.getText().equals(GitCommands.keys()); 

    } 
    else 
    { 
     System.out.println("Key could not be found"); 
    } 
} 
+1

你试过了什么?你使用什么编程语言?也许一些你已经尝试过的代码片段可能会帮助你获得相关答案 – 2014-08-28 08:59:47

+0

您好Bogdan - 我正在使用Java,并且我只有当前的代码片段我正在处理其他版本,并且已经很久没有删除了 – user3373261 2014-08-28 09:00:54

+1

在这里添加你的代码片段开始 – 2014-08-28 09:02:59

回答

1

您可以使用java.util.Properties API使用方法属性文件并将其加载到您的应用程序中并从中读取属性。

像这样:

Properties properties = new Properties(); 
ClassLoader classloader = Thread.currentThread() 
        .getContextClassLoader(); 
      is = classloader.getResourceAsStream(location);//location:your path of the properties file 
      properties.load(is); 

      properties.getProperty("Your Key"); 
+0

Daft问题,但我会把这个问题放在我的主要课程内?谢谢你的回答 - 如果可以的话,我会赞成! – user3373261 2014-08-28 09:25:42

+0

此外,我已经为我的Jtree专门加载了我的prop文件 - 所以会发生这种冲突还是需要现在编程它与您的代码段的不同? – user3373261 2014-08-28 09:32:21

+1

添加此代码,当你开始你的主要方法,它会加载proerties文件,我认为它不会冲突的JTree代码 – 2014-08-28 10:35:23