I am working on an assignment that open a text file and convert/save as sql file. I got how to open a text file but I am stuck on how to convert to sql file.
Here is code that I got for reading the text file
public static void main(String[] args) {
// The path to open the file.
String fileName = "input.txt";
String line = null;
try {
// The file reads text files
FileReader file = new FileReader(fileName);
// Wrap file in BufferedReader
BufferedReader bufferedReader = new BufferedReader(file);
while ( (line = bufferedReader.readLine()) != null ) {
System.out.println(line);
}
// Close files
bufferedReader.close();
} catch ( FileNotFoundException ex ) {
System.out.println("Unable to open file '" + fileName + "'");
} catch ( IOException ex ) {
ex.printStackTrace();
}
}
Can you anybody give me some hint how to save a text file as sql file after reading the text file?
Thank you so much!
Modify your try block like below. There are two functions added
List<String> parseLine(String line)andString createInsert(List<String> headers, List<String> rowData)Implement the first using simple String tokenization and then createInsert is used by simple string concatenations.