gpt4 book ai didi

java - 从文件读取直到 Java 中的特定字符

转载 作者:搜寻专家 更新时间:2023-10-31 08:07:31 24 4
gpt4 key购买 nike

我有一个包含 sql 查询的文本文件。
每个查询都以“;”结尾。
我想执行这些查询。
这是我的问题;我想读文件直到“;”然后执行我读过的查询。
我可以阅读和执行单行查询,但我无法阅读超过一行的整个查询。

这是我写的代码;

try {
String komut = "";
BufferedReader bf = new BufferedReader(new FileReader("C:\\\\Users\\\\AhmetEmre\\\\Downloads\\\\text.txt"));

while ((komut = bf.readLine()) != null) {
if (komut.length() != 0) {
if (komut.charAt(komut.length() - 1) == ’;’) {
komutVektoru.add(komut);
komut = "";
} else {
komut += komut;
}
}
}

来自文本文件的示例;

**INSERT INTO tb_hukuk_ihbar ( id, hizmet_id, create_user_id, mektup_pdf, mektup_no, mektup_pdf_sayfa_no, ihbar_donemi)
VALUES
( 3672961, 1244494, 566, './FESIH20110721-123-001', '1107/001-003672961', 1, '201107');**
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672961, 55367968, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672961, 34811016, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672961, 53849639, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672961, 40120622, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672961, 49865422, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672961, 51456657, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672961, 41151378, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672961, 33450635, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672961, 37954783, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672961, 56885453, '94.6');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672961, 56893779, '86.5');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672961, 36398959, '14');
**INSERT INTO tb_hukuk_ihbar ( id, hizmet_id, create_user_id, mektup_pdf, mektup_no, mektup_pdf_sayfa_no, ihbar_donemi)
VALUES
( 3672962, 2458406, 566, './FESIH20110721-123-001', '1107/001-003672962', 2, '201107');**
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 53217996, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 51120970, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 36684544, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 40994810, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 38081806, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 49433813, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 35098768, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 30013966, '22');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 27578939, '22.85');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 28833729, '22');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 31258381, '18');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 55709156, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 33770763, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 32499838, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 39801860, '14');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 56882759, '81.7');
INSERT INTO tb_hukuk_ihbar_detay( ihbar_id, fatura_id, odenmeyen_miktar) VALUES( 3672962, 56942137, '98.7');

最佳答案

您可以使用 java.util.Scanner使用一个文件并将 ; 指定为 delimiter .

像这样:

Scanner scanner = new Scanner(new File("input.sql"));
scanner.useDelimiter(";");

while(scanner.hasNext()) {
System.out.println("SQL statement: " + scanner.next());
}

关于java - 从文件读取直到 Java 中的特定字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6786708/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com