一行一行读取文本文件,使用正则表达式判断.第一行开始它死活不认为是:"^"

szuzsq 2017-09-07 11:15:44
代表如下:

FileInputStream fis = new FileInputStream(in_fn);
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader reader = new BufferedReader(isr);

while((str = reader.readLine()) != null) {
str = str.trim();

//管理员表
Pattern pattern = Pattern.compile("^[\\u4E00-\\u9FA5]+表.*$");
Matcher matcher = pattern.matcher(str);
if(matcher.find()) {
String group = matcher.group();
table_name = group;
}
}



后来发现文本文件是utf的,前面有EF BB BF这3个bom....
然后reader读出来的第一行就不匹配"^[\\u4E00-\\u9FA5]+表.*$",,,
主要是它不认识前面"^".
后面第二行,第三行读出来的,它都认识"^"


即第一行"管理员表",它不认识,,,然后后面的"用户表",它能认识...
好神奇...

分数不够...下次再补...敬请原谅...



-------------------------------------------------------------------------------------------
我的文本文件如下:
管理员表
name admin
字段
名称 类型 属性 说明
ID int ID
company_id int 公司ID.外键.-1为总公司
department_id int 部门ID.外键
role_id int 角色ID.外键.-1为系统管理员
account string 账号名
password string 密码
salt string 加密私钥
openid string 微信公众号的openid
unionid string 微信公众号的unionid
name string 名称
tel string 座机
mobile string 手机
email string 邮箱
sex int 性别:0:男;1:女
age double 年龄
city_code string 城市编码.国家统计局数据.即身份证前6位.如:440224
address string 地址
time int 日期.unix时间戳
索引
名称 属性 说明
company_id company_id
department_id department_id
role_id role_id
account account(32)
mobile mobile(12)
email email(32)
openid openid(32)
unionid unionid(32)
name name(32)
city_code city_code(6)


用户表
name user
字段
名称 类型 属性 说明
ID int ID
recommend_id int 推荐人ID.外键.-1为无推荐人
account string 账号名
password string 密码
salt string 加密私钥
openid string 微信公众号的openid
unionid string 微信公众号的unionid
name string 名称
tel string 座机
mobile string 手机
email string 邮箱
sex int 性别:0:男;1:女
age double 年龄
city_code string 城市编码.国家统计局数据.即身份证前6位.如:440224
address string 地址
company string 公司
industry string 行业
department string 部门
job string 职务
salary double 收入
identity string 身份证
identity_front_image string 身份证正面照片
identity_back_image string 身份证反面照片
time int 日期.unix时间戳
索引
名称 属性 说明
recommend_id recommend_id
account account(32)
mobile mobile(12)
email email(32)
openid openid(32)
unionid unionid(32)
name name(32)
city_code city_code(6)
identity identity(18)

-------------------------------------------------------------------------------------------
...全文
318 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
soton_dolphin 2017-09-07
  • 打赏
  • 举报
回复
保存没有bom的UTF-8文本文件
李德胜1995 2017-09-07
  • 打赏
  • 举报
回复
用editplus等工具打开文本存为编码为utf-8无Bom的。。。。。

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧