Java regular expressions, replacing pictures, replacing numbers, harmonizing words, copying files

Source: Internet
Author: User
Tags create directory

/**
* INDEXOF ("character", position int)//In the method, enter only the first property by default to find the character in the property from the beginning, and the position int to find the character from the input int position
* LASTINDEXOF ("character")// From the string, find the character in the last property
* str= "www.oracle.com";//substring intercept String
* str.substring (4,10)//intercept from fourth to 10th bit
* Str.substring (4)//intercept from fourth bit to end
* Str.charat (4)//intercept string fourth character
* Boolean startwith ("Thi"), Endwith ("Ava")// Determines whether the string starts with thi, determines whether the string ends with Ava
* str.toupercase,str.tolowercase//string all converts to uppercase//string all to lowercase
* string.valueof (i)// Converts the base type to a string
* regex= "[a-za-z0-9_][email protected][a-za-z0-9_]+ (\\.[ a-za-z]+) + "//mailbox Regular Expression
* Boolean match=<string>mail.matches (Regex)//string supports regular expression-related methods Boolean match= Mail.matches (regex);
* string[] Data=str.split ("[0-9]+");//Split the number part, get all the letter part
* File.canread (); File.canwrite (); File.ishidden (); File.getabosolutepath (); File.exist (); File.mkdir ();//create directory file. Directory ()//boolean directories
* file[] subs=file.listfiles ();//returns subkeys in the File directory to the Subs array subs.getname () Gets the subkey name
* The high concurrency of the computer says that multiple programs run concurrently, that is, multithreading runs
*
*/

/** Replace picture name
* public static void Main (string[] args)
{
String imgname= "1234.jpg";
String[] Data=imgname.split ("\ \");
Imgname=system.currenttimemillis () + "." +data[1];//1. To the right of the number, 0 indicates the left side of the number.
System.out.println (imgname);
}
* */
/** Replace the number part with String.replaceall ("regex", "str")
* public static void Main (string[] args)
{
String str= "ABC123DEF456GHI789JKL";

Str=str.replaceall ("\\d+", "#NUMBER #");//"\\d+" represents the number part
System.out.println (str);
}
* */
/** Harmonious language
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);
}
*/
/** search function, get directory under "." The beginning of the subkey
* public static void Main (string[] args)
{
File File=new file (".");
FileFilter filter=new FileFilter () {
/**
* Add filter condition as long as the parameter given by the file is considered
* Meet the requirements, then return True
*
Public boolean accept (file file)
{
String Name=file.getname ();
System.out.println ("Filtering:" +name);
Return Name.startswith (".");
}
};
File[] Subs=file.listfiles (filter);
for (int i=0;i<subs.length;i++)
{
System.out.println (Subs[i].getname ());
}
}
*/
/** Copying files
* public static void Main (string[] args) throws IOException
{
/**
* The idea of implementing File replication:
* Use RAF to read each byte sequentially from the source file
* and write to another file
*
Randomaccessfile rw=new randomaccessfile ("Movie_cp.mp4", "RW");
Randomaccessfile r=new randomaccessfile ("Movie.mp4", "R");
/**
* Used to save every byte read to
*
*
int d=-1;
Long Start=system.currenttimemillis ();
while ((D=r.read ())!=-1)//means! Read to last file
{
Rw.write (d);
}
Long end =system.currenttimemillis ();
System.out.println ("Copy done! Time consuming: "+ (End-start) +" MS ");

R.close ();
Rw.close ();
}
}
* */

Java regular expressions, replacing pictures, replacing numbers, harmonizing words, copying files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.