이 코드를 작성하여 파일을 읽은 다음 파일의 각 이름에 대해 표시를 요청합니다. 그리고 마크가 40 이상이면 pass와 below가 실패하고 각각의 이름을 해당 파일에 씁니다. 여기 while(namesFile.hasNext()
내 코드는 다음과 같습니다 :텍스트 파일 읽기 및 쓰기
import java.io.*;
import java.util.*;
public class TestResults {
public static void main(String[] args) {
String errs = "";
Scanner k = new Scanner(System.in);
try {
try (
Scanner namesFile = new Scanner(new File("Names.txt"));
PrintWriter passFile = new PrintWriter("Pass.txt");
PrintWriter failFile = new PrintWriter("Fail.txt");) {
while (namesFile.hasNext()) {
try {
String tempLine = namesFile.nextLine();
System.out.println("Please Enter Mark For " + tempLine + " : ");
int mark = k.nextInt();
if (mark >= 40) {
passFile.println(tempLine + " " + mark + "%");
} else {
failFile.println(tempLine + " " + mark);
}
} catch (InputMismatchException ime) {
String valueStr = namesFile.next();
errs += "\n\t" + valueStr;
} finally {
namesFile.close();
passFile.close();
failFile.close();
}
}
}
} // Checks to see if file is there.
catch (IOException ioe) {
System.out.println("ERROR: " + ioe.getMessage());
}
}
}
오류 메시지는 무엇을 말하는가하지만 라인 27에서 오류가? – Fildor
왜 시도하고 있습니까? { – Rahul
코드를 올바르게 작성하십시오. – Rahul