Read in file for constants #java

前端 未结 2 737
耶瑟儿~
耶瑟儿~ 2021-01-26 17:12

I want to read in a datafile that has several constants for my program (e.g. MAXARRAYSIZE).
I then want these constants to be accessible anywhere in my program by typing som

2条回答
  •  一向
    一向 (楼主)
    2021-01-26 18:00

    Use a static bloc in ConstantsClassName class.

    public class ConstantsClassName{
        public static final  String MAXARRAYSIZE;
        static{
            // read your file and store the data in;
            MAXARRAYSIZE = valueRetrievedFromFile;
        }
    }
    

    MAXARRAYSIZE should be MAX_ARRAY_SIZE if you follow Java conventions for constants declaration.

提交回复
热议问题