小编Tag*_*rag的帖子

从RandomAccessFile读取数据产生不正确的结果 - Java

我有一个42行的文本文件.每行包含超过22,000个以逗号分隔的数字.

我想从每一行中提取某些数字,并且我有一个长度为1000的int数组,其中包含从这42行中的每一行中需要的1,000个数字.

例如,如果数组包含43,1,3244,则意味着我需要从第一行到第42行开始的第43个数字,第1个数字和第3244个数字.

我的for循环似乎不起作用,它只读取文本文件中第一行有42行220000个数字,我不知道它出错了.

for(int i=0;i<42;i++){ //irretates through the 42 lines of 
    counter=1; // to keep track about on which line the code is working
    System.out.println("Starting line"+i);

    st2=new StringTokenizer(raf1.readLine(),",");
    //raf3 is a RandomAccessFile object containing the 42 lines

    a:while(st2.hasMoreTokens()){
        b=is_there(array2,counter);
        // is_there is a method that compares the rank of the taken being read with 
       //the whole array that has the 1000 numbers that i want. 
        if(b==false){ 
            // if the rank or order of token [e.g. 1st, 432th] we are …
Run Code Online (Sandbox Code Playgroud)

java for-loop stringtokenizer randomaccessfile

7
推荐指数
2
解决办法
886
查看次数