Java Regex,替換圖片,替換數字,和諧用語,複製檔案

來源:互聯網
上載者:User

標籤: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_][email protected][a-zA-Z0-9_]+(\\.[a-zA-Z]+)+"//郵箱的Regex
* boolean match=<String>mail.matches(regex)//字串支援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 Regex,替換圖片,替換數字,和諧用語,複製檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.