Quantities
id Input
from 1
to   2

intervals
 [0,1) [1,2) [2,3);
id Output
from 1
to   2

intervals
[0,2) [2,4)  [4,6); Situations    #1: 1  1      
   #2:   1  2
   #3: 1  3     
   #4:   2  1
   #5: 2  2         
   #6:   2  3
   #7: 3  2 
            #8:   3  3 Transitions    #:1 1 #:1 2 #:1 3 #:1 4 #:1 5 #:1 6 #:1 7 #:1 8 
   #:2 1 #:2 2 #:2 3 #:2 4 #:2 5 #:2 6 #:2 7 #:2 8 
   #:3 1 #:3 2 #:3 3 #:3 4 #:3 5 #:3 6 #:3 7 #:3 8 
   #:4 1 #:4 2 #:4 3 #:4 4 #:4 5 #:4 6 #:4 7 #:4 8 
   #:5 1 #:5 2 #:5 3 #:5 4 #:5 5 #:5 6 #:5 7 #:5 8 
   #:6 1 #:6 2 #:6 3 #:6 4 #:6 5 #:6 6 #:6 7 #:6 8 
   #:7 1 #:7 2 #:7 3 #:7 4 #:7 5 #:7 6 #:7 7 #:7 8 
   #:8 1 #:8 2 #:8 3 #:8 4 #:8 5 #:8 6 #:8 7 #:8 8 需要读取Input intervals 下的3个区间 最好是数值型的 存入一个数组 Interval[] intervals 中
已经有 class Interval (double lower, double upper) {}
Output 的 intervals 下的3个区间 存入另一个数组读取 Situations 下 8种情况,存入一个数组中 如第一种情况  #1: 1 1  对应着 Input [0,1)和  Ouput [0,2)
读取 Transitions 下的所有情况,也存入一个数组中  比如    #:  1 2  对应  Situation 1  和 Situation 2  

解决方案 »

  1.   

    用StringTokenizer加不同的delimit挨个读取就行了,只是判断复杂些。
      

  2.   

    先分开把每个段读取到一个字符串中:
    然后对特定的段进行特定的字符串分解:使用StringTokenizer
    然后就是体力活了。
      

  3.   


    StringTokenizer有点过时了吧。用String的split()方法吧。用正则分解。
      

  4.   

    例如有一个字符串:"a b         c               d".
    delim是" ", 即结果是只要其中中的a,b,c,d
    如果只是简单地使用String.split来做,你看看结果是什么就明白了,如果自己去构造一个复杂的,那你首先得学习正则表达式。
    StringTokenizer则可以简单的处理好这一问题。
      

  5.   

    用Scanner应该能实现,麻烦一点
      

  6.   

    Scnner的next序列会忽略空白字符。
      

  7.   

      import java.io.*;/** * 使用FileInputStream读取文件 */public class ReadFile1 {         public static void main(String[] args) {                   //声明流对象                   FileInputStream fis = null;                                     try{                            //创建流对象                            fis = new FileInputStream("e:\\a.txt");                            //读取数据,并将读取到的数据存储到数组中                            byte[] data = new byte[1024]; //数据存储的数组                            int i = 0;  //当前下标                            //读取流中的第一个字节数据                            int n = fis.read();                            //依次读取后续的数据                            while(n != -1){ //未到达流的末尾                                     //将有效数据存储到数组中                                     data[i] = (byte)n;                                     //下标增加                                     i++;                                      //读取下一个字节的数据                                      n = fis.read();                            }                                                        //解析数据                            String s = new String(data,0,i);                            //输出字符串                            System.out.println(s);                   }catch(Exception e){                            e.printStackTrace();                   }finally{                            try{                                     //关闭流,释放资源                                     fis.close();                            }catch(Exception e){}                   }         }}
      

  8.   

    用了你的方法,但是报错  java.lang.ArrayIndexOutOfBoundsException: 1024
    at ReadFile1.main(ReadFile1.java:33)       1024这么多都不够?
      

  9.   

    private void initQuantities(String name){
            //open text file name.txt to readout the quantities
            try {
                //initialize file to read from
                BufferedReader component;
                component = new BufferedReader(new FileReader(name + ".txt"));
                
                //initialize empty list of quantities
                quantityList = new SqmaQuantity[0];
                
                String line; //String to readout lines
                
                //read lines until expression "Quantities" is found
                while (((line = component.readLine()) != null) 
                        && (line.indexOf("Quantities") == -1)) {
                }
                
                //read every line until end of file
                while ((line = component.readLine()) != null) {
                    
                    //create new quantity if expression "id" is found
                    if (line.indexOf("id ") != -1) {
                        //copy quantityList to elongate it
                        SqmaQuantity[] tempList = 
                            new SqmaQuantity[quantityList.length + 1];
                        System.arraycopy(
                                quantityList, 0, tempList, 0, quantityList.length);
                        tempList[tempList.length - 1] =
                            new SqmaQuantity(tempList.length);
                        quantityList = new SqmaQuantity[tempList.length];
                        System.arraycopy(
                                tempList, 0, quantityList, 0, tempList.length);
                    }
                }
                
                //close file
                component.close();
                
                //open text file name.txt again to readout the intervals
                component = new BufferedReader(new FileReader(name + ".txt"));            int quantityIndex = 0; //index of current quantity
                
                //read lines until end of file
                while (((line = component.readLine()) != null)) {
                    //analyse next line if expression "intervals" is found               
                    if (line.indexOf("intervals") != -1) {
                        //readout next line
                        line = component.readLine();
                        
                        char character; //current character in the line 
                        int valueBegin = 0; //beginning of a value in the interval 
                        int valueEnd = 0; //end of a value in the interval
                        
                        //initialize new interval
                        SqmaInterval interval = new SqmaInterval();
                        
                        //read every character in the line
                        int i;
                        for (i = 0; i < line.length(); i++) {
                            //read character
                            character = line.charAt(i);
                            
                            //if character is a left bracket...  
                            if (character == '[' || character == '(') {
                                //...set bracket and beginning of the first value
                                interval.setLeftBracket(character);
                                valueBegin = i + 1;
                            }
                            
                            //if character is a comma...
                            if (character == ',') {
                                //...set end of the first value
                                valueEnd = i;
                                
                                //extract the value from the line
                                String substr = line.substring(valueBegin,
                                        valueEnd);
                                if (substr.equals("?"))
                                    interval.setLowerValue(
                                            Double.NEGATIVE_INFINITY);
                                else
                                    interval.setLowerValue(
                                            Double.parseDouble(substr));
                                
                                // set beginning of the 2nd value
                                valueBegin = i + 1;
                            }
                            
                            //if character is a right bracket... 
                            if (character == ']' || character == ')') {
                                
                                //...set bracket and end of the second value
                                interval.setRightBracket(character);
                                valueEnd = i;
                                
                                //extract the value from the line
                                String substr = line.substring(
                                        valueBegin, valueEnd);
                                if (substr.equals("?"))
                                    interval.setUpperValue(
                                            Double.POSITIVE_INFINITY);
                                else
                                    interval.setUpperValue(
                                            Double.parseDouble(substr));
                                
                                //add completed intervall to the quantitiy
                                quantityList[quantityIndex].addInterval(interval);
                                
                                //initialize next interval
                                interval = new SqmaInterval();
                            }
                        }
                        //increase index to handle next quantity
                        quantityIndex++;
                    }
                    
                    //readout direction of the signal if character "#" is found
                    if (line.indexOf("#") != -1) {
                        char direction = line.charAt(line.indexOf("id") + 3);
                        int index = (line.charAt(2) - '0') - 1;
                        quantityList[index].setDirection(direction);
                    }
                }
                //close file
                component.close();
            } 
            catch (IOException ioe) {
                ioe.printStackTrace();
            }        
        }这是读取Quantity 和 它下面的Intervall的数据 似乎不是很好用,高手帮忙看看吧