我的代码没有从文件中读取该行。但我不确定为什么。初级Java,任何输入都是有帮助的。
谢谢。
public class ReverseWords {
public static void main(String [] args){
Scanner in = new Scanner(System.in);
System.out.print("Enter File Name: ");
String fileName = in.nextLine();
File f = new File(fileName);
try {
Scanner input = new Scanner(f);
int n = input.nextInt();
String line = input.nextLine();
System.out.println(line);
String [] words = line.split(" ");
for(int i=0; i<words.length; i++){
System.out.println(words[i]);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}