import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class ReadF{
public static void main(String[] args) {
String fileName = "test.txt";
try {
// 1. create a bufferedReader for reading files
BufferedReader reader = new BufferedReader(new FileReader
(fileName));
// 2. read out content, print them out line by line
String line;
String [] letterList;
String[][] bookingStatus = new String[10][10];
int floor = 0;
while ((line = reader.readLine()) != null) {
letterList = line.split(" ");
for (int i = 0 ; i < letterList.length ; i++) {
bookingStatus[floor][i] = letterList[i];
}
floor++;
}
System.out.println("Booking Status of Room 001 is: " +
bookingStatus[0][0]);
System.out.println("Booking Status of Room 002 is: " +
bookingStatus[0][1]);
System.out.println("Booking Status of Room 003 is: " +
bookingStatus[0][2]);
System.out.println("Booking Status of Room 101 is: " +
bookingStatus[1][0]);
System.out.println("Booking Status of Room 102 is: " +
bookingStatus[1][1]);
System.out.println("Booking Status of Room 103 is: " +
bookingStatus[1][2]);
reader.close();
// 3. error handling
}
catch (IOException e) {
e.printStackTrace();
}
}
}
想問如果我想INPUT個ROOM NO,去CHECK個ROOM既STATUS,而唔係好係依家甘,要自己寫bookingStatus[1][1], 即係bookingStatus[floor][room], eg我INPUT201,佢會CHECK bookingStatus[1][0]個STATUS,甘我要點改呀??