The program needs to be written in Java Code: You are given a file containing th
ID: 3668648 • Letter: T
Question
The program needs to be written in Java Code: You are given a file containing the names and addresses of company employees from many years ago that your manager has asked you to import into a database. You can use a CSV file and your database application to load the file, but the file your manager gave you was exported from an old, non-standard accounting system. Here is its format: Freddy|Kruger 1313|Mockingbird|Lane Houston|Texas Billy|Thornton 1010|Slingblade|Street Houston|Texas Write a program that reads in the file and exports it to a standard CSV format. For the records above, the output format would be Freddy Kruger,1313 Mockingbird Lane, Houston, Texas Billy Thornton,1010 Slingblade Street, Houston, Texas
Explanation / Answer
package com.manager.test;
import java.io.FileWriter;
import java.io.IOException;
public class GenerateCsv
{
public static void main(String [] args)
{
generateCsvFile("c:\test.csv");
}
private static void generateCsvFile(String sFileName)
{
try
{
FileWriter writer = new FileWriter(sFileName);
writer.append("Freddy");
writer.append("Kruger 1313");
writer.append('Mockingbird');
writer.append("Lane Houston");
writer.append("Thornton 1010");
writer.append('Slingblade');
writer.append("Street Houston");
//generate whatever data you want
writer.flush();
writer.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.