1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | String fileName = "D:/date.java.bak";// String fileName = "D:/test.qqq";String line;inti = 0, j = 0, f = 0, k = 0;try{BufferedReader in = newBufferedReader(newFileReader(fileName));line = in.readLine();while(line != null) {// System.out.println(line);charc[] = line.toCharArray();for(inti1 = 0; i1 < c.length; i1++) {// 如果是字母if(Character.isLetter(c[i1]))i++;// 如果是数字elseif(Character.isDigit(c[i1]))j++;// 是空格elseif(Character.isWhitespace(c[i1]))f++;}line = in.readLine();k++;}in.close();System.out.println("字母:"+ i + ",数字:"+ j + ",空格:"+ f + ",行数:"+ k);} catch(IOException e) {e.printStackTrace();} |