我需要允許用戶告訴程序文件在哪裏,並以特定方式輸出該數據。我似乎無法將數據傳遞給單獨的類文件。我究竟做錯了什麼?使用File IO(Java)接收來自方法的輸入
import java.util.Scanner;
import java.io.*;
public class Student_Test {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in); // sets up scanner
System.out.print("Enter file name: "); //user provides file name and location
String userFile = in.nextLine(); // accepts input from user
File file = new File(userFile); //uses the file method to import the data
Scanner inputFile = new Scanner(file); // uses scanner to read the data
System.out.print(inputFile.Out());
}
}
我也可以有一些關於如何啓動一個單獨的學生班來做這項工作的提示。我將閱讀的文件有多行文字。我將不得不採取一些文本,並將其轉換爲整數。然後我必須以某種方式輸出它。我應該使用void方法還是返回方法?
學生課程將給出一個文本文件,其中包括學生人數,每個學生的姓名和每個學生的3個分數。 '<學生人數>''學生姓名'''''''......每個元素都在自己的行中。 –
frillybob
也許將學生班級重命名爲Classroom.At至少這是對我有意義的。一個教室有學生,一個學生有一個名字和一些分數 – cssGEEK