码迷,mamicode.com
首页 > 编程语言 > 详细

Java 正则表达式,替换图片,替换数字,和谐用语,复制文件

时间:2017-11-07 23:59:57      阅读:480      评论:0      收藏:0      [点我收藏+]

标签:rect   substring   正则表达   搜索功能   www   close   hidden   实现   gen   

/**
* indexOf("字符",位置int) //在方法中,只输入第一个属性默认从头开始查找属性中的字符,位置int表示从输入的int位置之后查找字符
* lastIndexOf("字符") //从字符串中,查找最后一个属性中的字符
* str="www.oracle.com"; //substring截取字符串
* str.substring(4,10) //从第四位截取到第10位
* str.subString(4) //从第四位截取到末尾
* str.charAt(4) //截取字符串中第四个字符
* boolean startwith("thi"),endwith("ava") //判断字符串是否以thi开始,判断字符串是否以ava结尾
* str.toUperCase,str.toLowerCase //字符串全部转换为大写 //字符串全部转换为小写
* String.valueOf(i) //将基本类型转换为字符串
* regex="[a-zA-Z0-9_]+@[a-zA-Z0-9_]+(\\.[a-zA-Z]+)+" //邮箱的正则表达式
* boolean match=<String>mail.matches(regex) //字符串支持正则表达式相关方法 boolean match=mail.matches(regex);
* String[] data=str.split("[0-9]+"); //拆分掉数字部分,得到所有的字母部分
* file.canRead(); file.canWrite(); file.isHidden(); file.getAbosolutePath(); file.exist(); file.mkdir();//创建目录 file.Directory()//boolean目录
* File[] subs=file.listFiles(); //返回file目录下的子项到subs数组中 subs.getName()获取子项名称
*计算机的高并发运行说的是多个程序同时运行,也就是多线程运行
*
* */

/**替换图片名称
* 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<subs.length;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();
}
}
* */

Java 正则表达式,替换图片,替换数字,和谐用语,复制文件

标签:rect   substring   正则表达   搜索功能   www   close   hidden   实现   gen   

原文地址:http://www.cnblogs.com/yangHD/p/7801559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!