2016-11-12 12 views
0

私がやっていることは、標準のコンソール入力ではなく入力テストケースをファイルから読み込んで別のファイルに書き戻させることです。 ここに問題が出てくるのですが、ファイルを使って入力をしようとすると、が返されます。しかし、私はカスタム入力を与えようとすると正しい出力を出しますcmd)を実行し、出力をファイルに出力します。ここでファイルから標準出力(コンソール)を読み込んで出力を他のファイルに出力する

は私のサンプルプログラムです:

public class Roman 
{ 
static private final String INPUT = "Q4.in"; 
static private final String OUTPUT = "Q4.out"; 

    // open I/O files 


public static void main(String[] args) 
{ 
    FileInputStream instream = null; 
    PrintStream outstream = null; 

    try { 
     instream = new FileInputStream(INPUT); 
     outstream = new PrintStream(new FileOutputStream(OUTPUT)); 
     System.setIn(instream); 
     System.setOut(outstream); 
    } catch (Exception e) { 
     System.err.println("Error Occurred."); 
    } 
    int i; 
    Scanner sc=new Scanner(System.in); 

    int T=sc.nextInt(); 

    Num2Rom[] tc=new Num2Rom[T]; 

    for(i=0;i<T;i++) 
    { tc[i]=new Num2Rom(); } 

    System.out.println(T+"\n"); 

    for(i=0;i<T;i++) 
    { tc[i].display(i+1); } 
    } 
} 

ArrayList<String> wordList; 

Num2Rom() 
{ 
    Scanner sc = new Scanner(System.in); 
    while(sc.hasNext()){ 
    String numeral = sc.nextLine(); 
    System.out.println("print"+numeral); 
    numeral = numeral.toUpperCase(); 

    String[] words = numeral.split(" "); 
    wordList = new ArrayList<>(Arrays.asList(words)); } 
} 

入力は次のようにフォーマットされて:あなたはに入力を与えるためにjavaコマンドラインarguementsを使用することができます

2 
Eight 
Twenty 

答えて

0

プログラム。

class A{ 
public static void main(String args[]){ 

for(int i=0;i<args.length;i++) 
System.out.println(args[i]); 

} 
} 

引数を文字列形式で受け取ると、引数を目的の型に変換します。

あなたがintegereをしたい場合は、使用して変換することができますよう

int value=Integer.parseInt($args[0]); 
関連する問題