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