0

好吧,我从没想过在编程时我需要走这么远,但我被困住了..

我正在为我需要构建的东西构建某种引擎,并且出现“预期”错误。

这让我发疯,因为所有来源都是正确的(至少我是这么认为的)。

资源:

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..
4

1 回答 1

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
   {
    ...
   }
于 2012-07-23T10:04:41.090 回答