0

I have a input txt file which is of format

T1, 4, 8
T2, 1, 40
T3, 2, 9
T4, 3, 15

How to store the values of that text file that are split by commas in an array?

In commented code, the error I get is Type mismatch: cannot convert from String to int

import java.util.Scanner;
import java.io.*;

public class FCFS {

    public static void main(String args[]) throws IOException {
        String process_name[], tmp[];
        int tat[], wt[];
        int priority[];
        int burst_time[];
        int i = 0, avg_tat = 0, avg_wt = 0;
        String line = null;

        try {
            Scanner Keyboard = new Scanner(System.in);
            System.out.print("Enter the file name ");
            String fileName = Keyboard.nextLine()
            FileReader file = new FileReader(fileName);
            BufferedReader myReader = new BufferedReader(file);
            while ((line = myReader.readLine()) != null) {

                // process_name[i] = line.split(",")[0];
                //priority  [i] = line.split(",")[1];

                //burst_time  [i] = line.split(",")[2];
                i++;
            }
        } catch (FileNotFoundException e) {
            System.out.println("An error occurred.");
            e.printStackTrace();
        }


    }
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

0 Answers0