好吧,我从来没有想过在编程时我会需要这么做,但我卡住了..
我正在为我需要构建的东西构建某种引擎,并且我收到了“预期”错误。
它让我发疯,因为所有来源都是正确的(至少我是这么认为的)。
来源:
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..
答案 0 :(得分: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
{
...
}