package lwl.youweb2.test;

 import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern; /**
* 查找指定文件中指定字符的个数
*
* @author liuwenlong
* @create 2020-08-20 10:48:27
*/
@SuppressWarnings("all")
public class test01 {
static {
String args[] = {"d:\\123.txt", "张三"};
main(args);
} public static void main(String[] args) {
if (args.length != 2) {
return;
}
BufferedReader br = null;
FileReader fr = null;
try {
fr = new FileReader(args[0]);
br = new BufferedReader(fr);
int cnt = 0;
String str = null;
while ((str = br.readLine()) != null) {
Pattern a = Pattern.compile(args[1]);
Matcher m = a.matcher(str);
while (m.find()) {
cnt++;
}
}
System.out.println("[" + args[1] + "]的数量:" + cnt);
} catch (Exception e) {
System.err.println(e.getMessage());
} finally {
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} }

Java查找指定文件中指定字符的个数的更多相关文章

  1. java:从指定问价中读取80个字节写入指定文件中

    import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; public class F ...

  2. 通过 mysqlbinlog 和 grep 命令定位binlog文件中指定操作

    1.binlog日志基本知识 MySQL的二进制日志binlog可以说是MySQL最重要的日志,它记录了所有的DDL和DML语句(除了数据查询语句select),以事件形式记录,还包含语句所执行的消耗 ...

  3. linux 中 如何 搜索 指定目录 下 指定文件 的 指定内容

    开发时,经常遇到 全局查找某些代码 linux 中 如何 检索 某 目录下指定文件 的 指定内容如下: //.点为查找当前目录 下 的 所有 *.php 文件里 有 hello 的文件 find . ...

  4. Android中查找一个Layout中指定的子控件

    我们通常希望查找一个页面中指定类型的控件,单个控件知道id很容易找到,但是如果是多个呢?或者说是在程序中自定义的控件,且不知道id怎么办呢?如想找到页面中的Spinner,可用以下方法 /** * 从 ...

  5. 自定义VBS脚本(统计在指定文件中搜索字符串出现的次数)

    '=========================================================================='' VBScript Source File - ...

  6. 通过wget工具下载指定文件中的URLs对应的资源并保存到指定的本地目录中去并进行文件完整性与可靠性校验

    创建URLs文件在终端输入cd target_directory回车,便把当前文件夹切换到了目标文件夹target_directory,此后创建的文件都会丢它里面在终端输入cat > URLs回 ...

  7. Java笔记13:统计文件中每个字符出现的次数

    一.代码实现 import java.io.*; import java.util.*; /** 功能:统计文件中每个字符出现的次数 思路: 1.定义字符读取(缓冲)流 2.循环读取文件里的字符,用一 ...

  8. APACHE2.4 指定目录中的字符编码

    APACHE2.4 指定目录中的字符编码 xampp 的 apache2.4 默认字符编码是西文,中文字符显示乱码,在 httpd.conf 没有 AddDefaultCharset utf-8 这样 ...

  9. flink---实时项目--day01--1. openrestry的安装 2. 使用nginx+lua将日志数据写入指定文件中 3. 使用flume将本地磁盘中的日志数据采集到的kafka中去

    1. openrestry的安装 OpenResty = Nginx + Lua,是⼀一个增强的Nginx,可以编写lua脚本实现⾮非常灵活的逻辑 (1)安装开发库依赖 yum install -y ...

随机推荐

  1. springboot多环境部署(profile多环境支持)

    springboot多环境部署(profile多环境支持) 背景   项目开发过程中会有开发环境(dev),测试环境(test)和生产环境(prod),不同的环境需要配置不同的配置,profile提供 ...

  2. MSF常用命令备忘录

    msf下的命令 set session x:设置要攻击的session #监听端口反弹PHP shell use exploit/multi/handler set payload php/meter ...

  3. python关于函数调用作为参数的说明&&装饰器

    python关于函数调用作为参数的说明&&装饰器 简单的: 先看代码: def out(): print('out') def inner(): return 'inner' retu ...

  4. Oracle元数据信息

    一.schema操作 1)查看当前schema select user, sys_context('userenv','current_schema') from dual; 2)切换schema a ...

  5. Clion使用gtk3

    在已经安装了gtk3的情况下,使用Clion还是无法正常给gtk3. 此时,我们需要更改CMakeList. 以下代码中需要添加的行都以#开头,此仅为了标识需要添加的行,而无需在实际代码中添加# cm ...

  6. 报错:无效的列类型: 1111;must be specified for all nullable parameters.

    org.springframework.jdbc.UncategorizedSQLException: Error setting null parameter. Most JDBC drivers ...

  7. 【luogu4137】 Rmq Problem / mex - 莫队

    题目描述 有一个长度为n的数组{a1,a2,…,an}.m次询问,每次询问一个区间内最小没有出现过的自然数. 思路 莫队水过去了 233 #include <bits/stdc++.h> ...

  8. 推荐一看的blog

    不同专题: 个人blog cnblogs.com/MiLog cnblogs.com/Dway (指DeepWay) cnblogs.com/muly 建议一看,主要发布在cnblogs.com/dl ...

  9. Linux系统修改服务器系统时间

    修改Linux系统时间,需要执行两个命令,如下: 第一条指令:date –s '2017-07-12 10:22:30' 第二条指令:clock –w //将日期写入CMOS

  10. HYSBZ - 2243 树链剖分 + 线段树 处理树上颜色段数

    用线段树处理颜色段数 记录区间内的颜色段数,区间右端点的颜色,区间右端点的颜色. int tr[maxn<<2], lc[maxn<<2], rc[maxn<<2] ...