java正则替换数字_Java 正则表达式,替换图片名称,替换数字,和谐用语,复制文件...

/**替换图片名称

* public static void main(String[] args)

{

String imgName="1234.jpg";

String[] data=imgName.split("\\.");

imgName=System.currentTimeMillis()+"."+data[1];//1表示.号的右边,0表示.号的左边

System.out.println(imgName);

}

* */

/**将数字部分替换 String.replaceAll("regex","str")

* public static void main(String[] args)

{

String str="abc123def456ghi789jkl";

str=str.replaceAll("\\d+", "#NUMBER#");//"\\d+"表示数字部分

System.out.println(str);

}

* */

/**和谐用语

public static void main(String[] args)

{

String regex="(wqnmlgdsb|cnm|nc|tmd|mdzz|mmp|djb)";

String message="wqnmlgdsb!nizhegenc!mdzz!nigedjb!";

message=message.replaceAll(regex,"****");

System.out.println(message);

}

*/

/**搜索功能,获取目录下以"."开头的子项

* public static void main(String[] args)

{

File file=new File(".");

FileFilter filter=new FileFilter() {

/**

* 添加过滤条件,只要认为参数给定的file

* 满足要求,则返回true即可

*

public boolean accept(File file)

{

String name=file.getName();

System.out.println("正在过滤:"+name);

return name.startsWith(".");

}

};

File[] subs=file.listFiles(filter);

for(int i=0;i

{

System.out.println(subs[i].getName());

}

}

*/

/**复制文件

* public static void main(String[] args) throws IOException

{

/**

* 实现文件复制的思路:

* 使用RAF从源文件中顺序读取每个字节

* 并写入到另一个文件中

*

RandomAccessFile rw=new RandomAccessFile("movie_cp.mp4","rw");

RandomAccessFile r=new RandomAccessFile("movie.mp4","r");

/**

* 用于保存读取到的每个字节

*

*

int d=-1;

long start=System.currentTimeMillis();

while((d=r.read())!=-1)//表示!读取到最后一个文件

{

rw.write(d);

}

long end =System.currentTimeMillis();

System.out.println("复制完成!耗时:"+(end-start)+"ms");

r.close();

rw.close();

}

}

* */

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值