작성하려고하는 일부 코드에서 메소드에 문제가 있습니다. 기본적으로이 메서드는 텍스트 파일에있는 정수를 다른 메서드 (setStrength, setAccuracy 등)로 전달해야합니다. 아래의 소스 코드와 텍스트 파일이 첨부되어 있습니다. 가능한 한 어떤 식 으로든 도와주세요. 고맙습니다! 대상 문자열 적절한 정수 포맷이 아닌 상기 문자열을 정수로 해석하려고하면텍스트 파일 읽기 Java, 숫자 형식 예외
public static void loadGame(String loadFileName) {
System.out.println();
try {
System.out.println("Finding file...");
FileInputStream loadFileStream = new FileInputStream("/Users/Tyler/eclipse-workspace/myfirsttextgame/src/myfirsttextgame/" + loadFileName + ".txt");
System.out.println("Loading Game...");
Scanner inputStream = new Scanner("/Users/Tyler/eclipse-workspace/myfirsttextgame/src/myfirsttextgame/" + loadFileName + ".txt");
while (inputStream.hasNext()) {
player.setStrength(Integer.parseInt(inputStream.next()));
System.out.println("Strength Loaded");
player.setAccuracy(inputStream.nextInt());
player.setHeight(inputStream.nextInt());
player.setWeight(inputStream.nextInt());
player.setStamina(inputStream.nextInt());
}
System.out.println("Character Loaded Successfully.");
} catch (IOException e) {
System.out.println("Exception Occurred:");
e.printStackTrace();
}
}
txt 파일이 첨부되어 있는데 찾을 수 없습니다. –
** 어떻게 ** 플레이어 **를 선언 했습니까? 'Players players = new Players();'** players ** 클래스는 ** public **으로 ** setStrength (**), ** setAccuracy (**) 메소드 등이 선언되어 있습니까? – DevilsHnd