为什么我的txt文件不停循环?

时间:2014-08-03 16:22:26

标签: java text-files continue

我一直在忙着我的任务,当我正在执行会员资格的移除程序时,我发现了这个错误。那么,代码有什么问题?最后,当我键入成员ID时,它会不停地循环。我用println对它进行了测试,并继续打印。

  while(scC.hasNext()){
  removeMemId = scC.next();
  removeName = scC.next();
  removeAddress = scC.next();
  removeIcNo = scC.next();
  removePhoneNo = scC.next();
  removeMemberType = scC.next().charAt(0);
  removeScanDate = scC.next();
  removeExpiryDate = scC.next();
  removeYoga = scC.nextInt();
  removeKickboxing = scC.nextInt();
  removeAerobics = scC.nextInt();

  if(iRemoveMemId.equals(removeMemId))
  continue;

  else{



            FileWriter fileWriteRemove = new FileWriter(fileCorporate2.getName(),true);
            BufferedWriter buffWriteRemove = new BufferedWriter(fileWriteRemove);
            buffWriteRemove.write(removeMemId+",");
            buffWriteRemove.write(removeName+",");
            buffWriteRemove.write(removeIcNo+",");
            buffWriteRemove.write(removeAddress+",");
            buffWriteRemove.write(removePhoneNo+",");
            buffWriteRemove.write(removeMemberType+",");
            buffWriteRemove.write(removeScanDate+",");
            buffWriteRemove.write(removeExpiryDate+",");
            buffWriteRemove.write(removeYoga+",");
            buffWriteRemove.write(removeKickboxing+",");
            buffWriteRemove.write(removeAerobics+",");
            buffWriteRemove.close();
             }

  }
    scC.close();
    removeCorporate.close();
    fileCorporate.delete();
    fileCorporate2.renameTo(fileCorporate);
    System.out.println("Your membership has been succesfully removed.");
    System.out.println("You will be redirect back to home page\n\n");

1 个答案:

答案 0 :(得分:0)

你不应该在while循环中多次调用next()。

您可以将next()存储为临时变量,然后将该变量用于迭代

使用类似的东西:

  while(scC.hasNext()){
  Object temp = scC.next();
  removeMemId =temp;
  removeName = temp;
  removeAddress = temp;
  removeIcNo = temp;
  removePhoneNo = temp;
  removeMemberType = temp.charAt(0);   
  .....

但它可能不一定是您的问题的原因。