好吧,這是代碼,我需要以某種方式從文本文件中取出一行並轉換爲數組對象。像P [0] = 「asdasdasd」如何從文本文件中選取一行並將其轉換爲數組對象?
public class Patient2 {
public static void main(String args[])
{
int field = 0;
String repeat = "n";
String repeat1 = "y";
Scanner keyIn = new Scanner(System.in);
// FILE I/O
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("Patient.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
ArrayList<Patient1> patients=new ArrayList<Patient1>();
Patient1 p =new Patient1();
//set value to the patient object
patients.add(p);
System.out.println(p);
}
}
對於想要轉換爲數組的行的模式以及要設置它的位置,您可以更具體一些嗎? – 2012-02-01 04:51:03