파일을 열고 싶습니다. int
숫자를 나타내는 문자열을 읽고 순서대로 입력하십시오. int n6 = inputStream.nextInt();
을 읽지 마십시오. int n6
코드를 제거하면 작동합니다. 이것은 주 코드입니다. 제 6 번째가 올바른 위치에 없다는 것을 알고 있습니다. 이것이 작동하지 않는다는 것을 보여주는 것입니다. 또한 도움이된다면 NetBeans를 사용하고 있습니다.텍스트 파일에서 숫자를 읽을 수 없습니다
번호는 다음과 같습니다 5, -3, 3, 8, 4, 0
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.NoSuchElementException;
Scanner inputStream = null;
try {
inputStream = new Scanner(new FileInputStream("stuff.txt"));
} catch(FileNotFoundException e) {
System.out.println("File not found");
System.exit(0);
} catch(NoSuchElementException e) {
System.out.println("Error");
System.exit(0);
}
int n1 = inputStream.nextInt();
int n2 = inputStream.nextInt();
int n3 = inputStream.nextInt();
int n4 = inputStream.nextInt();
int n5 = inputStream.nextInt();
int n6 = inputStream.nextInt();
inputStream.nextLine();
String line = inputStream.nextLine();
System.out.println(n2);
System.out.println(n1);
System.out.println(n3);
System.out.println(n5);
System.out.println(n4);
System.out.println(n6);
inputStream.close();
당신은 아마도'nextLine' 호출이 필요하지 않습니다. – MadProgrammer
작동합니다. 고맙습니다. – raiderX2G3
글쎄, 좋은 변화를;) – MadProgrammer