Java Filter All HTML tags, copy files to the specified location

Source: Internet
Author: User

public static string filterhtml (String string) {string str = String.replaceall ("<[a-za-z]+[1-9]?[ ^><]*> "," "). ReplaceAll (" </[a-zA-Z]+[1-9]?> "," "); return str;}

  

Copy the file to the specified location public static Boolean Inputstreamtofile (InputStream instream, String targetfile) {FileOutputStream fs = null; Try{file target = new File (targetfile); File dir = Target.getparentfile (); if (!dir.exists ()) {dir.mkdirs ();} if (target.exists ()) {Target.delete ();}  Target.createnewfile (); fs = new FileOutputStream (target); byte[] buffer = new Byte[1024];int Byteread = 0;while ((byteread = instream.read (buffer))! =-1) {fs.write (buffer, 0, byteread);} return true;} catch (Exception e) {e.printstacktrace (); return false;} FINALLY{IF (fs! = NULL) {Try{fs.close ();} catch (IOException e) {e.printstacktrace ();}} if (instream! = null) {Try{instream.close ();} catch (IOException e) {e.printstacktrace ();}}}}

  

     Public Static Boolean CopyFile (File source, String targetfile)    {        try        {            new  fileinputstream (source);             return inputstreamtofile (instream, targetfile);        }         Catch (FileNotFoundException e)        {            e.printstacktrace ();             return false ;        }            }

Java Filter All HTML tags, copy files to the specified location

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.