要单独从Java文件中获取insert语句吗

要单独从Java文件中获取insert语句吗,java,regex,Java,Regex,我有一个文本文件,如: insert into table values (‘test’, <xml> </xml>); insert into table values (‘test’, <xml> <xml> <xml> </xml>); insert into table values (‘test’, <xml> <xml> <xml> <xml> <

我有一个文本文件,如:

insert into table 
values (‘test’,
<xml> 
</xml>);
insert into table 
values (‘test’,
<xml> 
<xml>
<xml>
</xml>);
insert into table 
values (‘test’,
<xml> 
<xml>
<xml>
<xml>
<xml>
</xml>);
插入到表中
值('测试',
);
插入表格
值('测试',
);
插入表格
值('测试',
);
现在我希望我能在程序中分别读取每个
insert
(完整语句)命令,并在表中执行


我怎么能这么做?任何正则表达式都会有帮助吗?

你是说类似的东西吗

 String str = "insert into table \n"
            + "values (‘test’,\n"
            + "<xml> \n"
            + "</xml>);\n"
            + "insert into table \n"
            + "values (‘test’,\n"
            + "<xml> \n"
            + "<xml>\n"
            + "<xml>\n"
            + "</xml>);\n"
            + "insert into table \n"
            + "values (‘test’,\n"
            + "<xml> \n"
            + "<xml>\n"
            + "<xml>\n"
            + "<xml>\n"
            + "<xml>\n"
            + "</xml>);";

    String[] commands = str.split(";");
    for(String command : commands)
    {
        System.out.println(command + ";");
    }
String str=“插入表\n”
+“值('测试',\n”
+“\n”
+“”;\n“
+“插入到表中\n”
+“值('测试',\n”
+“\n”
+“\n”
+“\n”
+“”;\n“
+“插入到表中\n”
+“值('测试',\n”
+“\n”
+“\n”
+“\n”
+“\n”
+“\n”
+ ");";
String[]commands=str.split(“;”);
用于(字符串命令:命令)
{
System.out.println(命令+“;”);
}
收益率:

insert into table 
values (‘test’,
<xml> 
</xml>);

insert into table 
values (‘test’,
<xml> 
<xml>
<xml>
</xml>);

insert into table 
values (‘test’,
<xml> 
<xml>
<xml>
<xml>
<xml>
</xml>);
插入到表中
值('测试',
);
插入表格
值('测试',
);
插入表格
值('测试',
);

将文件内容读入字符串。然后使用String.split()

String s=“插入表值('test',);插入表值
(‘测试’,”
+“”;插入表值('test',
);";
字符串[]test=s.split(“;”);
对于(int i=0;i
如果您一次读取文件,您可以在完整字符串输入中使用split

若并没有,那个么在读取文件时可以尝试使用缓冲区,在遇到查询分隔符时进行拆分,并一直这样做直到文件结束

 String s = "insert into table values (‘test’,<xml> </xml>); insert into table values             
 ( ‘test’,<xml>" 
 + "<xml><xml></xml>); insert into table values (‘test’,<xml> <xml><xml><xml><xml>    
 </xml>);";
 String[] test = s.split(";");
 for(int i = 0; i < test.length; i++) {
    System.out.println(test[i]);
 }