CSVファイルを私のオフィスのすべてのプリンタのインストーラを作成するために書いたバッチファイルとマージします。 xeroxTemplate.txtファイルは、書式設定の問題を引き起こしていた場合のためにtxtとして名前を変更したバッチファイルです。スキャナ入力の問題
実行すると、最初の "for"ループで次のエラーがスローされます。私は、ファイル内容
java.util.NoSuchElementException: No line found
public class PrinterScriptCreator {
public static void main(String[] args) {
Scanner csvScanner = new Scanner("printers.csv");
csvScanner.useDelimiter(",");
Scanner txtScanner = new Scanner("xeroxTemplate.txt");
try{
while(csvScanner.hasNext()){
//create file with name from first csv cell
FileWriter fw = new FileWriter(csvScanner.next());
PrintWriter pw = new PrintWriter(fw);
//copy first 7 lines from xeroxTemplate.txt
for(int i=0; i<7; i++){
pw.println(txtScanner.nextLine());
}
//copy the next three cells from CSV into new file
for(int i=0; i<3; i++){
pw.println(csvScanner.next());
}
//copy remaining lines from TXT to the new file
while(txtScanner.hasNextLine()){
pw.println(txtScanner.nextLine());
}
}
} catch (IOException ex) {
System.out.printf("ERROR: %s\n", ex);
}
}
}
、これを試してみてください。それを見つけてここに貼り付けたコードに(コメントを追加して)ハイライトします。 –