在java方法中从cvs文件读取一串字符串数据,使用matches方法进行数字正则匹配,总是返回false;
// 获取Object,返回结果为OSSObject对象 OSSObject object = ossTools.getObject(mallCouponDirect.getFilename()); // 获取Object的输入流 InputStream objectContent = object.getObjectContent(); BufferedReader br = new BufferedReader(new InputStreamReader(objectContent,"utf8")); String s = ""; List uidList = new ArrayList(); while((s = br.readLine())!=null){ System.out.println(s);//打印结果是:159042459 boolean a = s.matches("[0-9]+");//a 总是false if(a){ //...other codes } } }
如果在while循环里直接把s设为“159042459”,a为true;
I always wonder if the content read in your
cvs
contains other invisible characters?