源代码如下:
import java.util.*;
import java.io.*;
public class Test {

public static void main(String[] args) throws IOException{
//Map<String,String> map=new TreeMap();
FileInputStream fr=new FileInputStream(new File("E:\\JAVA\\project\\workspace\\File\\temp\\endnote"));
List<String> list=new ArrayList<String>();
Iterator<String> it=list.iterator();

fr.skip(5);
int len=fr.read();
while(len!=-1){
int i=0;
if(len==37){
byte[] buff=new byte[10000];
fr.skip(2);
while((len=fr.read())!=10){
buff[i]=(byte)len;
i++;
}
String a=new String(buff);//buff-wrong,被后面的覆盖
System.out.println(a+' ');
list.add(a);
}else {
len=fr.read();
continue;
}
len=fr.read();
}
while(it.hasNext()){
System.out.println(it.next()+' ');
}

}}endote的内容如下:
 %A Fukui, Kenji
%A Kosaka, Hiromichi
%A Kuramitsu, Seiki
%A Masui, Ryoji
%T Nuclease activity of the MutS homologue MutS2 from Thermus thermophilus is confined to the Smr domain
%0 Journal Article
%D 2007
%J Nucl. Acids Res.
%R 10.1093/nar/gkl735
%P gkl735
%V 
%N 
%U http://nar.oxfordjournals.org/cgi/content/abstract/gkl735v1
%8 January 10, 2007
%X MutS homologues are highly conserved enzymes engaged in DNA mismatch repair (MMR), meiotic recombination and other DNA modifications. Genome sequencing projects have revealed that bacteria and plants possess a MutS homologue, MutS2. MutS2 lacks the mismatch-recognition domain of MutS, but contains an extra C-terminal region called the small MutS-related (Smr) domain. Sequences homologous to the Smr domain are annotated as  proteins of unknown function' in various organisms ranging from bacteria to human. Although recent in vivo studies indicate that MutS2 plays an important role in recombinational events, there had been only limited characterization of the biochemical function of MutS2 and the Smr domain. We previously established that Thermus thermophilus MutS2 (ttMutS2) possesses endonuclease activity. In this study, we report that a Smr-deleted ttMutS2 mutant retains the dimerization, ATPase and DNA-binding activities, but has no endonuclease activity. Furthermore, the Smr domain alone was stable and functional in binding and incising DNA. It is noteworthy that an endonuclease activity is associated with a MutS homologue, which is generally thought to recognize specific DNA structures.运行结果却是
Exception in thread "main" java.util.ConcurrentModificationException
我想把endnote每一行的内容以String的形式放进list,这个程序应该怎么写?

解决方案 »

  1.   

    请确认你的文件名是否写错?
    在这里“E:\\JAVA\\project\\workspace\\File\\temp\\endnote”
    加上文件名的后缀是试试看。
      

  2.   

    ConcurrentModificationException同时被两个或两个以上修改?
      

  3.   

    believefym(feng)
    ConcurrentModificationException同时被两个或两个以上修改?
    应该怎么解决?
      

  4.   

    JDK文档:
    当方法检测到对象的并发修改,但不允许这种修改时,抛出此异常。 例如,某个线程在 Collection 上进行迭代时,通常不允许另一个线性修改该 Collection。通常在这些情况下,迭代的结果是不明确的。如果检测到这种行为,一些迭代器实现(包括 JRE 提供的所有通用 collection 实现)可能选择抛出此异常。执行该操作的迭代器称为快速失败 迭代器,因为迭代器很快就完全失败,而不会冒着在将来某个时间任意发生不确定行为的风险。 注意,此异常不会始终指出对象已经由不同 线程并发修改。如果单线程发出违反对象协定的方法调用序列,则该对象可能抛出此异常。例如,如果线程使用快速失败迭代器在 collection 上迭代时直接修改该 collection,则迭代器将抛出此异常。 注意,迭代器的快速失败行为无法得到保证,因为一般来说,不可能对是否出现不同步并发修改做出任何硬性保证。快速失败操作会尽最大努力抛出 ConcurrentModificationException。因此,为提高此类操作的正确性而编写一个依赖于此异常的程序是错误的做法,正确做法是:ConcurrentModificationException 应该仅用于检测 bug。
      

  5.   

    首先,换个文件名,试试看是不是第一次之后第二次开始才出现异常如果是的话,
    加上
    try{
    }catch(){
    }finally{
       try{
         fr.close
       }catch(){
       }
    }
    重起你的机器执行程序
      

  6.   

    文件名没有问题,我把while(it.hasNext()){
    System.out.println(it.next()+' ');
    }这段删掉就好了,没异常了.还有
    byte[] buff=new byte[10000];
    改为byte[] buff=new byte[3000];