如何在java中为静态变量赋值?

时间:2015-08-04 03:31:08

标签: java web-services webserver

所以我有一个静态变量有一个默认值。如何分配来自文本文件的值?我试图打印来自文本文件及其工作的值,但不能将值分配给静态变量。这是我的代码:

    int iCounter = 0;
    static int iCounterMin = 1;
    static int iCounterMax = 101;
    int spCounter = 101;
    static int spCounterMin = 100;
    static int spCounterMax = 201;
    int csCounter = 201;
    static int csCounterMin = 200;
    static int csCounterMax = 601;
    int hliCounter = 601;
    static int hliCounterMin = 600;
    static int hliCounterMax = 701;
    int hlpCounter = 701;
    static int hlpCounterMin = 700;
    static int hlpCounterMax = 801;
    int counter1 = 0;
    int counter2 = 0;
    int counter3 = 0;
    int counter4 = 0;
    int counter5 = 0;
    int counter6 = 0;
    static List <Integer> numbers = new ArrayList<>();

    public static void main(String []args){
           try {
                for (String line :              Files.readAllLines(Paths.get("C://file.txt"))) {
                 for (String part : line.split(",")) {

                     try {
                     Integer i = Integer.valueOf(part);
                     numbers.add(i);

                     } catch (Exception a) {

                     }
                }
            }

            // Asign Values
            iCounterMin = numbers.get(0);
            iCounterMax = numbers.get(1);
            System.out.println(iCounterMin + " " + iCounterMax);

            spCounterMin = numbers.get(2);
            spCounterMax = numbers.get(3);

            csCounterMin = numbers.get(4);
            csCounterMax = numbers.get(5);

            hliCounterMin = numbers.get(6);
            hliCounterMax = numbers.get(7);

            hlpCounterMin = numbers.get(8);
            hlpCounterMax = numbers.get(9);

            for(int i=0; i <= 9; i++){
                System.out.println(numbers.get(i));
            }
            } catch (Exception e){

            }

           //Invoke PagIBIGDisplay
           java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PagIBIGDisplay().setVisible(true);
            }
            });
      }

0 个答案:

没有答案