Reading whitespace with scanner

I am trying to have my scanner read a line but, it's only reading one word. I need it to read the next three words and assign them.
package com.hunt.game;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Scanner;

import com.hunt.game.combat.diseases.Diseases;
import com.hunt.game.combat.shrines.Shrines;

public class GameLoader {
	
	Shrines shrine = new Shrines();
	
	public Scanner x;
	
	public void openFile(){
		try{
			x = new Scanner(new File("C:/Users/AncientPandas/Desktop/HuntersConquest/player.txt"));
		} catch (Exception e){
			System.out.println("Could not load previous save file.");
		}
	}
	
	public void readFile(){
		
		try{
			
		while(x.hasNext()){
			int attack = x.nextInt();
			int defense = x.nextInt();
			int life = x.nextInt();
			int maxLife = x.nextInt();
			int currentExperience = x.nextInt();
			int experienceToLevel = x.nextInt();
			int level = x.nextInt();
			int statPoints= x.nextInt();
			boolean disease = x.nextBoolean();
			boolean blessing = x.nextBoolean();
			String diseaseName = x.next();
			String shrineName = x.next();
			
			Player.atk = attack;
			Player.def = defense;
			Player.currentLife = life;
			Player.maxLife = maxLife;
			Player.exp = currentExperience;
			Player.exptoLevel = experienceToLevel;
			Player.level = level;
			Player.statPoints = statPoints;
			Player.disease = disease;
			Player.blessing = blessing;
			Diseases.diseaseName = diseaseName;
			shrine.shrineName = shrineName;
		}
		} catch (Exception e) {
			System.out.println("Corrupted File... Overwriting previous save file");
			NewGame();
		}
	}
	
	public void closeFile(){
		x.close();
	}
	
public void NewGame(){
		
		GameLoader gl = new GameLoader();
		Main main = new Main();
		Scanner scanner = new Scanner(System.in);
		int choice;
		
		System.out.println("Are you sure you would like to overwrite your previous save data?\n"
				+ "(1) Yes\n(2) No");
		choice = scanner.nextInt();
		do{
			if(choice == 1){
				try{
					File player = new File ("C:/Users/AncientPandas/Desktop/HuntersConquest/player.txt");
					FileOutputStream fos = new FileOutputStream(player);
					OutputStreamWriter osw = new OutputStreamWriter(fos);
					Writer writer = new BufferedWriter(osw);
					// What to write to file
					writer.write(String.valueOf(Player.atk));
					writer.write("\n");
					writer.write(String.valueOf(Player.def));
					writer.write("\n");
					writer.write(String.valueOf(Player.currentLife));
					writer.write("\n");
					writer.write(String.valueOf(Player.maxLife));
					writer.write("\n");
					writer.write(String.valueOf(Player.exp));
					writer.write("\n");
					writer.write(String.valueOf(Player.exptoLevel));
					writer.write("\n");
					writer.write(String.valueOf(Player.level));
					writer.write("\n");
					writer.write(String.valueOf(Player.statPoints));
					writer.write("\n");
					writer.write(String.valueOf(Player.disease));
					writer.write("\n");
					writer.write(String.valueOf(Player.blessing));
					writer.write("\n");
					writer.write(String.valueOf(Diseases.diseaseName));
					writer.write("\n");
					writer.write(String.valueOf(shrine.shrineName));
					System.out.println("Successfully overwrote file.");
					writer.close();
					main.run();
				} catch (IOException e){
					System.err.println("An error has occured while saving game...");
			}
		} else gl.openFile(); gl.readFile(); gl.closeFile();
	} while (choice != 1 && choice != 2);
}
}
Sign In or Register to comment.