Skip to content
Advertisement

Read from one text file and write into two text files

I need to read from one text file(carsAndBikes.txt) and the write in either cars.txt or bikes.txt carsAndBikes contains a list of cars and bikes and the first character of each name is C or B (C for Car and B for Bike). So far i have that but its showing cars and bikes content. Instead of the separated content.(CARS ONLY OR BIKES ONLY)

JavaScript

Advertisement

Answer

You’re checking if the input filename starts with a c instead of checking if the line read starts with a c.

You should also open both your output files before your loop, and close them both after the loop.

JavaScript
Advertisement