Reading from a text file
I'm attempting to read in a from the following from a txt file and prints out the first line and all the lines that begins with an attacker, until it gets to a a defender win or attacker win and then prints the rest of the file. However st is taking both the Attacker and part of Name, which is somehow throwing a NoSuchElementException. I only want it to take the Attacker, not part of the Name. I can't figure out why it's doing this and how to correct it.
Text File:
Attacker Name Here
Weapons:+10% Shields:+10% Armour:+10%
TypeS.CargoL.CargoL.FighterH.FighterCruiserB.ShipCol. ShipRecy.Esp. ProbeBomberDest.RipBattlecr
Num1111111111111
Weapon55551654401.10055101.1002.200220.000770
Shields112711275522011011055055055.000440
Armour4401.3204401.1002.9706.6003.3001.7601108.25012.100990.0007.700
Defender Name Here
Weapons:+10% Shields:+10% Armour:+10%
TypeS.CargoL.CargoL.FighterH.FighterCruiserB.ShipCol. ShipRecy.Esp. ProbeBomberSol. SatDest.RipBattlecrMiss.L.LaserH.LaserGaussIon.CPlasmaS.DomeLS.Dome
Num1111111111111111111111
Weapon55551654401.10055101.10012.200220.000770881102751.2101653.30011
Shields1127112755220110110550155055.00044022271102205503302.20011.000
Armour4401.3204401.1002.9706.6003.3001.7601108.25022012.100990.0007.7002202208803.85088011.0002.20011.000
The attacking fleet fires a total of 18 times with the total power of 1.059.543 upon the defender.
The defender's shields absorb 18.910 damage points.
The defending fleet fires a total of 33 times with the total power of 1.922.677 upon the attacker.
The attacker's shields absorb 38.730 damage points.
Attacker 1
TypeB.ShipCol. ShipRip
Num001
Weapon1.10055220.000
Shields22011055.000
Armour6.6003.300990.000
Defender 1
TypeS.CargoL.CargoL.FighterH.FighterCruiserB.ShipCol. ShipEsp. ProbeBomberDest.RipBattlecrMiss.L.LaserIon.CS.DomeLS.Dome
Num00000000001000000
Weapon55551654401.1005501.1002.200220.0007708811016511
Shields1127112755220110055055055.00044022275502.20011.000
Armour4401.3204401.1002.9706.6003.3001108.25012.100990.0007.7002202208802.20011.000
The attacking fleet fires a total of 11 times with the total power of 2.276.933 upon the defender.
The defender's shields absorb 17.510 damage points.
The defending fleet fires a total of 47 times with the total power of 9.540.458 upon the attacker.
The attacker's shields absorb 15.761 damage points.
Attacker 1
TypeRip
Num0
Weapon220.000
Shields55.000
Armour990.000
Defender 1
TypeS.CargoB.ShipEsp. ProbeBomberDest.RipBattlecrS.DomeLS.Dome
Num000000000
Weapon51.10001.1002.200220.00077011
Shields11220055055055.0004402.20011.000
Armour4406.6001108.25012.100990.0007.7002.20011.000
The battle ends draw.
The attacker has lost a total of 10.178.000 units.
The defender has lost a total of 1.836.800 units.
At these space coordinates now float 1.776.210 Metal and 1.413.954 Crystal.
Code:
try
{
Scanner Reader =new Scanner(new File("CR.txt"));//Reads in the file.
//Reader.hasNext();
System.out.println(Reader.nextLine());
Reader.nextLine();
//System.out.println(Reader.nextLine());
//System.out.println(Reader.nextLine());
while(Reader.hasNext() && flag!=1)
{
line=Reader.nextLine();//Separates the file
StringTokenizer st =new StringTokenizer(line," ");
st.nextToken().trim();
if("Attacker".equals(st))
{
System.out.println(line);
}
if("The defender has won the battle!".equals(line) ||"The attacker has won the battle!".equals(line))
{
temp=line;
flag=1;
}
}
System.out.println();
System.out.println();
System.out.println();
System.out.println(temp);
while(Reader.hasNext())
{
line=Reader.nextLine();
System.out.println(line);
}
}
catch (FileNotFoundException e)
{
System.out.println("I/O Error, FileNotFound");
}
catch (NoSuchElementException e)
{
System.out.println("I/O Error");
}

