Java中读取文件遇到的坑

File file = new File(fileurl);

// 创建新数据

InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "UTF-8");//NOSONAR

BufferedReader br = new BufferedReader(isr);//NOSONAR--禁止sonar扫描

String str;

int num=0;//记录日志可能会在那些地方遇到问题

while ((str = br.readLine()) != null) {// 按行读取

中间写自己的处理逻辑,加上trycatch捕捉异常

try{

String ss[] = str.trim().split("\\|");// 注意此处是“|”java中的特殊字符,要转换成正则。否则会出错。

}catch(Exceptino e) {

num++;

logger.info(“read data is errror,num=”num+"reason:"+e.getMessage());

}

num++;

}

br.close();// 关闭流

你可能感兴趣的:(Java中读取文件遇到的坑)