Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THIS IS WHAT I HAVE SO FAR CAN YALL PLZ HELP I WILL RATE! import java.io.File; i

ID: 641035 • Letter: T

Question

THIS IS WHAT I HAVE SO FAR CAN YALL PLZ HELP I WILL RATE!

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Fileio {

    public static void main(String[] args) throws FileNotFoundException {
        // TODO Auto-generated method stub

        Scanner scan = new Scanner(new File("Fred.txt"));
       

        while (scan.hasNextLine()) {
            String scan1 = scan.next();

            scan1 = scan1.replaceAll("[\| ]", " ");

            String scan2 = scan.next();
           
            String[] parts = scan.nextLine().split("|",2);
           
                 for(String p: parts) {
                  System.out.println(p);
            }
           
           
               
          
            scan2 = scan2.replaceAll("[\|]", " ");
           

            String scan3 = scan.next();

            scan3 = scan3.replaceAll("[\| ]", ",");

            System.out.println(">>"+scan1 + "," + scan2 + "," + scan3);


        }
        scan.close();

    }

}

Explanation / Answer

import java.io.*;
import java.util.*;
import java.net.*;

public class Test {

public static void main(String[] args) throws URISyntaxException,
IOException {

FileWriter writer = null;
File file = new File("D:/Datamatics Interview/SampleCSVFile.txt");
Scanner scan = new Scanner(file);
File file2 = new File("d:/CSV.csv");
file.createNewFile();
writer = new FileWriter(file2);

while (scan.hasNext()) {
String csv = scan.nextLine().replace("|", ",");
System.out.println(csv);
writer.append(csv);
writer.append(" ");
writer.flush();
}
}
}