文件结构:
中国:Chinese
蒙古:Mongolian
朝鲜:North Korean
韩国:South Korean
日本:Japanese
菲律宾:Philipinos
越南:Vietnamese
package com.soundai.nat.institution.admin.module;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.UUID;
public class Test2Controller {
public static void main(String[] args) throws IOException {
String sql = "INSERT INTO `sys_dict_data`(`uid`, `oid`, `dict_type`, `dict_label`, `dict_value`, `create_by`, `update_by`, `remark`, `is_publish`, `update_time`, `create_time`, `status`, `sort`) " +
"VALUES ('%s', %d, 'zhangjiakou.nation.list', '%s', '%s', 'admin', NULL, '备注信息', '1', NULL, '2021-12-02 18:42:31', 1, %d);";
//BufferedReader是可以按行读取文件
FileInputStream inputStream = new FileInputStream("C:\\Users\\14262\\Desktop\\new 1.txt");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String str = null;
int num = 1;
while((str = bufferedReader.readLine()) != null)
{
String[] mess = str.split(":");
String sqlResulrt = String.format(sql, UUID.randomUUID().toString().replaceAll("-", ""), num, mess[0].trim(), mess[1].trim(), num);
num++;
System.out.println(sqlResulrt);
}
//close
inputStream.close();
bufferedReader.close();
}
}
运行结果:
INSERT INTO
sys_dict_data
(uid
,oid
,dict_type
,dict_label
,dict_value
,create_by
,update_by
,remark
,is_publish
,update_time
,create_time
,status
,sort
) VALUES (‘e4ea0af9d84049d8921adb77907b402e’, 1, ‘zhangjiakou.nation.list’, ‘中国’, ‘Chinese’, ‘admin’, NULL, ‘备注信息’, ‘1’, NULL, ‘2021-12-02 18:42:31’, 1, 1);
INSERT INTOsys_dict_data
(uid
,oid
,dict_type
,dict_label
,dict_value
,create_by
,update_by
,remark
,is_publish
,update_time
,create_time
,status
,sort
) VALUES (‘856550cffb594148bbb4e200448904c7’, 2, ‘zhangjiakou.nation.list’, ‘蒙古’, ‘Mongolian’, ‘admin’, NULL, ‘备注信息’, ‘1’, NULL, ‘2021-12-02 18:42:31’, 1, 2);
INSERT INTOsys_dict_data
(uid
,oid
,dict_type
,dict_label
,dict_value
,create_by
,update_by
,remark
,is_publish
,update_time
,create_time
,status
,sort
) VALUES (‘d91bc43a601a4caea2b7c1025cb7a50e’, 3, ‘zhangjiakou.nation.list’, ‘朝鲜’, ‘North Korean’, ‘admin’, NULL, ‘备注信息’, ‘1’, NULL, ‘2021-12-02 18:42:31’, 1, 3);
INSERT INTOsys_dict_data
(uid
,oid
,dict_type
,dict_label
,dict_value
,create_by
,update_by
,remark
,is_publish
,update_time
,create_time
,status
,sort
) VALUES (‘98ee43198ab44972a485e753c44d22b6’, 4, ‘zhangjiakou.nation.list’, ‘韩国’, ‘South Korean’, ‘admin’, NULL, ‘备注信息’, ‘1’, NULL, ‘2021-12-02 18:42:31’, 1, 4);
INSERT INTOsys_dict_data
(uid
,oid
,dict_type
,dict_label
,dict_value
,create_by
,update_by
,remark
,is_publish
,update_time
,create_time
,status
,sort
) VALUES (‘1223954d25474945b595d8c66d942093’, 5, ‘zhangjiakou.nation.list’, ‘日本’, ‘Japanese’, ‘admin’, NULL, ‘备注信息’, ‘1’, NULL, ‘2021-12-02 18:42:31’, 1, 5);
INSERT INTOsys_dict_data
(uid
,oid
,dict_type
,dict_label
,dict_value
,create_by
,update_by
,remark
,is_publish
,update_time
,create_time
,status
,sort
) VALUES (‘f3ab83d2027f48d5b43d4b8fea00fd14’, 6, ‘zhangjiakou.nation.list’, ‘菲律宾’, ‘Philipinos’, ‘admin’, NULL, ‘备注信息’, ‘1’, NULL, ‘2021-12-02 18:42:31’, 1, 6);
INSERT INTOsys_dict_data
(uid
,oid
,dict_type
,dict_label
,dict_value
,create_by
,update_by
,remark
,is_publish
,update_time
,create_time
,status
,sort
) VALUES (‘a70420b0905340c6908f889b541bd5c5’, 7, ‘zhangjiakou.nation.list’, ‘越南’, ‘Vietnamese’, ‘admin’, NULL, ‘备注信息’, ‘1’, NULL, ‘2021-12-02 18:42:31’, 1, 7);