After locating the file flight.txt
, I have obtained the following flight information:
1 DFW BOM 2016-05-20 12:20 2016-05-21 02:40 1084.00 JetAirways 100
2 DFW DEL 2016-04-24 17:15 2016-04-25 07:20 1234.00 Lufthansa 100
3 DFW FRA 2016-06-05 13:30 2016-06-05 03:32 674.00 AmericanAirlines 100
The provided code demonstrates how to read a file in typescript:
populateFlightList() {
let data = fs.readFileSync('flight.txt').toString('utf-8'); {
let textByLine = data.split("\n")
console.log(textByLine);
};
I am now looking to iterate through the file, extract the necessary data and convert it into flight objects by creating new objects and adding them to an array list.
try {
Scanner fin = new Scanner(file);
while(fin.hasNext()) {
int number = fin.nextInt(); // Flight number
String from = fin.next(); // Departure airport
String to = fin.next(); // Arrival airport
}**Code in Java**
Is there a similar way to achieve this functionality in TypeScript?