0

I'm trying to write a code where I prompt a user to open a file given its directory. An excerpt of the data in the text file is shown below:

Example:

BAH, 1, 1

However, I want it to be displayed like so:

BAH

1

1

This is where I'm having a bit of problem. How would I use the delimiter to display it like the example above?

Here is my code:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class TextUI {
    @SuppressWarnings("resource")
    public static void main(String[] args) throws IOException {
    String line = null;
    Scanner user = new Scanner (System.in);
    System.out.print("Please, Enter The File Directory Of The File You Want To Open:");

    //Input file
    String filename = user.nextLine();
    File input = new File(filename);
    Scanner scan = new Scanner(input);


     FileReader fileReader = new FileReader(filename);

     // BufferedReader reads the text from an Input stream (like a file) by buffering characters that seamlessly reads characters, arrays or lines. 
     BufferedReader bufferedReader = new BufferedReader(fileReader);


     while((line = bufferedReader.readLine()) != null) {
    System.out.println(line);
     }
     }
}

This is the output where the user is prompted to enter a file directory:

Please, Enter The File Directory Of The File You Want To Open:C://Users//Tiffany//eclipse-workspace//Region1.txt

BAH, 1, 1
CAYM, 3, 7
CUBA, 5, 5
JAM, 5, 7
TCI, 7, 2
HAITI, 7, 5
DR, 8, 5

0 Answers0