标签:java
<span style="white-space:pre"> </span>@SuppressWarnings("resource") public static void getTxt(String filePath) { InputStreamReader inStreamReader=null; try { File file = new File(filePath); if (!file.isFile() || !file.exists()) { System.out.println("找不到指定文件!"); return; } else { inStreamReader = new InputStreamReader(new FileInputStream(file)); BufferedReader bufferedReader=new BufferedReader(inStreamReader); String lineTxt=null; int count = 0; while((lineTxt=bufferedReader.readLine())!=null){ //截取 int lineLength=lineTxt.length(); String subLineTxt=lineTxt.substring(1, lineLength-5); //分离 String[] subTxts=subLineTxt.split("_"); int subTxtsLength=subTxts.length; //正则表达式判断最后一个是否为数字 String lastTxt=subTxts[subTxtsLength-1]; if(!lastTxt.matches("\\d*")){ count++; System.out.println(lineTxt); } } System.out.println("总共有"+count); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally{ //关闭InputStream if(inStreamReader!=null){ try { inStreamReader.close(); } catch (IOException e) { e.printStackTrace(); } } } }
标签:java
原文地址:http://blog.csdn.net/wintersweetsugar/article/details/37053567