자바 메인함수에서 args 질문드립니다.
글쓴이: conan1447 / 작성시간: 목, 2020/05/21 - 4:52오후
public class Practice { public static void main(String[] args) throws Exception { // Check command line parameter usage if (args.length != 2) { System.out.println("Usage: java Practice John practice.txt"); System.exit(1); } // Check if file exists File file = new File("practice.txt"); if (!file.exists()) { System.out.println("File " + args[1] + " does not exist"); System.exit(2); } } }
인텔리제이로 위의 자바 코드를 작성했는데,
첨부한 그림대로,
edit configuration에서 Program arguments에 2개의 arg를 추가했는데도
if문이 실행되어 결과가 다음 같이 나오네요.
Usage: java Practice John practice.txt
Process finished with exit code 0
if문이 실행되지 않게 하려면 어떻게 해야 하나요?
File attachments:
첨부 | 파일 크기 |
---|---|
제목 없음.png | 99.11 KB |
Forums:
이런 문제에 부딛쳤을 때는...
이런 문제에 부딛쳤을 때는...
args.length 값이 무엇인지, args에는 어떤 값이 들어왔는지 출력하게 해 보면 문제 해결에 스스로 더 가까이 갈 수 있겠지요.
디버깅을 코드로 해야죠
실제 실행되는 인자를 모르는데 답이 나올리가 있나요
------------------------------------------------------------
ProgrammingHolic
댓글 달기