Create a java program that reads a .dat file which is fixed width and parse\'s t
ID: 3753689 • Letter: C
Question
Create a java program that reads a .dat file which is fixed width and parse's the patients information and then writes the file into a .csv file Using java libaries. The patients information in includes from left to right Patients Name, Address, City, State, Primary physican, Medical Alergies. below is some information that can be place within the .dat file.
patient.dat:
Full Name Address City State Primary Physican Medical allergies
Donald Trump 14527 Jefferson Ave Robinsdale ME Dr. Anderson Zyrtic
John Doe 11123 Roberson Dr New York City NY Dr. Lily None
Adolph Greyleaf 14378 Ginger Bread Rd Kansas City KS Dr. Rubertlongfellow Medroxyprogesterone
Explanation / Answer
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
public class Grades {
public static void main(String[] args) {
try {
//System.out.print("Enter the file name with extension : ");
FileWriter fw=new FileWriter("patient.csv");
Scanner scanner = new Scanner(System.in);
File file = new File("patient.dat");
scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String words[]=line.split(" +");
for(String i:words) fw.write(i+",");
fw.write(" ");
System.out.println(line);
}
fw.close();
scanner.close();
} catch (Exception ex) {
System.out.println("input file missing check once");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.