java - Convert a text file to a sql file -


i working on assignment open text file , convert/save sql file. got how open text file stuck on how convert sql file.

here code got reading text file

    public static void main(string[] args) {          // path open file.         string filename = "input.txt";         string line = null;          try {             // 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 open file '" + filename + "'");         } catch ( ioexception ex ) {              ex.printstacktrace();         }     } 

can give me hint how save text file sql file after reading text file?

thank much!

modify try block below. there 2 functions added list<string> parseline(string line) , string createinsert(list<string> headers, list<string> rowdata)

implement first using simple string tokenization , createinsert used simple string concatenations.

try {         // file reads text files          filereader file = new filereader(filename);          // wrap file in bufferedreader         bufferedreader bufferedreader = new bufferedreader(file);         list<string> headers;         string line = bufferedreader.readline();         if( line !=null ) { //got row header              headers = parseline(line);         }         list<string> rowdata;         while ( (line = bufferedreader.readline()) != null ) {             rowdata = parseline(line);             createinsert(headers, rowdata);         }         // close files         bufferedreader.close();     } catch ( filenotfoundexception ex ) {         system.out.println("unable open file '" + filename + "'");     } catch ( ioexception ex ) {          ex.printstacktrace();     } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -