-3
\$\begingroup\$

I have a text file shown below with different input types on a line that I am trying to read accordingly as shown below. I put the text file "Vehicle.txt" shown below directly in the src folder of my project. Yet from my CarRentalClient class with the main method.. my program tells me "Could not read file" when I try reading and printing the line. I am bad with handling input files so bear with my. My CarRentalClient class is below. What's wrong with it? Thanks

"Vehicle.txt"

“ECONOMY”, “PAB170”, “VIN1112”, “Nissan”, “Versa”, 30
“ECONOMY”, “PA171B”, “VIN1113”, “Toyota”, “Camry”, 28
“ECONOMY”, “PA172B”, “VIN1114”, “Toyota”, “Corolla”, 27
 “COMPACT”, “DE100A”, “VIN00001”, “Chevrolet”, “Cruze”, 25
 “COMPACT”, “DE200A”, “VIN00002”, “Nissan”, “Altima”, 25
 “COMPACT”, “DE300A”, “VIN00003”, “Mercedes”, “CLA”, 25
 “COMPACT”, “DE400A”, “VIN00004”, “BMW”, “350”, 23

CarRentalClient class

package Rental;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import Rental.Vehicle.VehicleType;
import Rental.Customer;
import Rental.CarReservation;

public class CarRentalClient {
//we are reading from a textFile and all that here

public static final String vehicleFileName =  "Vehicle.txt";
public static BufferedReader br = null;
public static FileReader fr = null;


CarReservation carReservation;
static VehicleType vehicleType;
static String vehicle;
Customer customer;
static String lPlate; static String vin; static String mke; static String mdl; static int mpg; static String vType;
static String cName; static long phoneNumber;

public static void parseReservationLine(String str){
    Scanner sc = new Scanner(str);
    sc.useDelimiter(",");

    while(sc.hasNext()){
        //vehicleType = VehicleType.valueOf(sc.next());
        vType = sc.next();
        cName = sc.next();
        phoneNumber = sc.nextLong();
        String sDate = sc.next();
        String eDate = sc.next();
    }
    sc.close();
}

public static void readVehicleFile(String line)
{
    Scanner sc = new Scanner(line);
    sc.useDelimiter(",");
    while(sc.hasNext()){
        //vehicleType = VehicleType.valueOf(sc.next());
        vehicle = sc.next();
        lPlate = sc.next();
        vin =  sc.next();
        mke = sc.next();
        mdl =  sc.next();
        mpg = sc.nextInt();     
    }

    sc.close();
}

//“ECONOMY”, “PA174B”, “VIN1116”, “Hyundai”, “Sonata”, 31 --- format for line input here

public static void main(String[] args)
{
    String vehicleFileName = "Vehicle.txt";
    String vehicleLine = null;
    try
    {
        fr = new FileReader(vehicleFileName);
        br = new BufferedReader(fr);
        while ((vehicleLine = br.readLine()) != null) {
            {
                readVehicleFile(vehicleLine);
                System.out.println(vehicleLine);
            }
        }
    }
    catch (IOException e) {
        System.out.println("Could not read file"); //exception handling
    }

    finally {
        try {
            if (br != null)
                br.close();

            if (fr != null)
                fr.close();

        } catch (IOException ex) {
            System.out.println("File IO is corrupted");
        }
    }
}


}
New contributor
user6952090 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$

closed as off-topic by πάντα ῥεῖ, 1201ProgramAlarm, Heslacher, Carcigenicate, Toby Speight Feb 11 at 18:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Heslacher, Carcigenicate, Toby Speight
If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.