2012-07-23 41 views
0

嗯,我从来没有想过我会需要编程时,走这么远,但我坚持..的Java - 错误而试图获得一些属性

我建立某种形式的引擎的东西,我需要建立,我得到一个“预期”的错误..

它使我疯狂,因为所有的来源是正确的(至少我认为是这样)。

源:在方法主体

import java.util.*; 
import java.io.*; 

public class Configurations { 

    // Storing the file locations in Strings. 
    public static String MOVE_FILE = "./configs/movement.properties"; 


    // Creating the needed variables for working-out stuff. 
    public static String HELLO_WORLD; 


    // Reading certain properties file and getting parameters. 
    Properties Props = new Properties(); // Asks me to put { { here.. 
    try { 
     Props.load(new FileInputStream(MOVE_FILE)); 
     HELLO_WORLD = Props.getProperty("MSG", "HelloWorld"); 
    } catch (IOException e) { 
     System.out.println(e); 
    } 

} // tells me to put }; } here.. 
+1

上面的代码不会编译。这是问题吗?你得到的预期错误是什么?我确定它包含一条有用的消息。读它可能是一个好主意。 – 2012-07-23 10:06:25

回答

2

穿戴陈述或者静态块。

public void methodName() 
{ 
    Properties Props = new Properties(); 
    try { 
     Props.load(new FileInputStream(MOVE_FILE)); 
     HELLO_WORLD = Props.getProperty("MSG", "HelloWorld"); 
     System.out.println(HELLO_WORLD); 
    } catch (IOException e) { 
     System.out.println(e); 
    } 
} 

或者

static 
    { 
    ... 
    } 
+0

好的,工作。 – 2012-07-23 10:08:11

+0

但我如何得到回显出HELLO_WORLD字符串? – 2012-07-23 10:08:34

+0

'System.out.println(HELLO_WORLD);' – adatapost 2012-07-23 10:09:20

相关问题