Step 1: Create a table
CREATE TABLE DLION ( _id INTEGER PRIMARY KEY AUTOINCREMENT, content TEXT, questionId INTEGER, answerId INTEGER, [right] INTEGER );
Step 2: edit the text content and place it in RES/raw/test.txt
Use Notepad ++ to open the file and put each row in the cell content of the table (Note: ^ indicates the beginning of the row $ indicates the end of the row)
Remove trailing spaces and blank lines: press Ctrl + H to select a regular expression -- search for the target: \ s + $ with null
Remove leading space from the line: press Ctrl + H to select the Regular Expression -- search Target: ^ \ s + with null
Step 3: Open the database details reference
Android SD card read database
Step 4: add data to a table
Public void addcontent () {try {bufferedreader localbufferreader = new bufferedreader (New inputstreamreader (getresources (). openrawresource (R. raw. test); DB = opendatabase (); For (INT I = Length + 1; I ++) {// Add the problem to the database string questionstr = localbufferreader. readline (); If (questionstr = NULL) {localbufferreader. close (); dB. close (); break;} log. V ("insert", "insert questioncontent" + question STR + "success! "); Db.exe csql (" insert into dlion (questionid, content) values ("+ I +", '"+ questionstr + "')"); // Add answer 1 to database string answerstr1 = localbufferreader. readline (); If (answerstr1 = NULL) {localbufferreader. close (); dB. close (); break;} log. V ("insert", "insert answercontent1" + answerstr1 + "success! "); Db.exe csql (" insert into dlion (answerid, content) values ("+ I +", '"+ answerstr1 + "')"); // Add answer 2 to database string answerstr2 = localbufferreader. readline (); If (answerstr2 = NULL) {localbufferreader. close (); dB. close (); break;} log. V ("insert", "insert answercontent2" + answerstr2 + "success! "); Contentvalues answercontent2 = new contentvalues (); answercontent2.put (" answerid ", I); answercontent2.put (" content ", answerstr2); dB. insert ("dlion", "_ id", answercontent2); // Add Answer 3 to database string answerstr3 = localbufferreader. readline (); If (answerstr3 = NULL) {localbufferreader. close (); dB. close (); break;} log. V ("insert", "insert answercontent3" + answerstr3 + "success! "); Contentvalues answercontent3 = new contentvalues (); answercontent3.put (" answerid ", I); answercontent3.put (" content ", answerstr3); dB. insert ("dlion", "_ id", answercontent3); // Add Answer 4 to database string answerstr4 = localbufferreader. readline (); If (answerstr4 = NULL) {localbufferreader. close (); dB. close (); break;} log. V ("insert", "insert answercontent4" + answerstr4 + "success! "); Contentvalues answercontent4 = new contentvalues (); answercontent4.put (" answerid ", I); answercontent4.put (" content ", answerstr4); dB. insert ("dlion", "_ id", answercontent4) ;}} catch (exception e) {// todo: handle exception E. printstacktrace ();}}