0

나는 테스터를 만드는 중입니다. 내가명령 줄 - FileNotFoundException

javac의의 WordListsTester.java 내가 파일 "하는 dictionary.txt을"이어야하지만, 그렇지 않은대로 오류 메시지를 표시해야한다고 생각

a.txt이 자바 WordListsTester을 시도

.

수정해야 할 사항은 무엇입니까?

public class WordListsTester { 
public static Scanner input = new Scanner(System.in); 

public static void main(String[] args) throws FileNotFoundException { 

    WordLists scrabble = new WordLists("dictionary.txt"); 

    String[] containLetter = scrabble.containsLetter(3, 'a'); 
    output(containLetter, "containsLetter.txt"); 

    String[] wordsStarts = scrabble.startsWith(3, 'a'); 
    output(wordsStarts, "startsWith.txt"); 

    String[] wordLength = scrabble.lengthN(3); 
    output(wordLength, "lengthN.txt"); 

    String[] multiLetter = scrabble.multiLetter(2, 'h'); 
    output(multiLetter, "multiLetter.txt"); 

    String[] vowelHeavy = scrabble.vowelHeavy(5, 2); 
    output(vowelHeavy, "vowelHeavy.txt"); 

    input.close(); 

} 

public static void output(String[] words, String fileName) { 
    try { 
     PrintWriter out = new PrintWriter(fileName); 
     if (words.length == 0) { 
      System.out.println("NO matched Words exist"); 
     } 
     for (int i = 0; i < words.length; i++) { 
      out.println(words[i]); 
     } 
     out.close(); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
     System.out.println("Invalid file name."); 
    } 
} 

}

+2

* 파일이 "dictionary.txt"*가되어야하는 이유는 무엇입니까? 당신은'a.txt'를 인자로 넘겨 주지만, 프로그램은 인자를 가지고 아무것도하지 않습니다. –

+0

내가 dictionary.txt를 읽어야 할 때, 올바르지 않은 a.txt를 전달할 때 오류를보고 싶습니다. –

+1

그런 다음 args [0]이 "dictionary.txt"와 같은지 확인하십시오. 그러나 유일하게 유효한 값이 "dictionary.txt"인 경우 인수를 전달하는 것이 무엇입니까? 그것은 "당신이 당신의 차의 색깔을 선택할 수 있지만 검은 색을 선택한 경우에만"과 약간 비슷합니다. –

답변

0
WordLists scrabble = new WordLists(args[0]); 

이 프로그램이 정확히 무엇을하는지 확실하지.

WordLists 클래스에서 파일 이름을 검사 할 것인지 확실하지 않습니다.

그러나 USER INPUT을 확인하려면 args [0]을 확인해야합니다.