• Java 过滤所有html标签,复制文件到指定位置


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

      

    复制文件到指定位置
    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
            {
                InputStream inStream = new FileInputStream(source);
                return inPutStreamTofile(inStream, targetfile);
            }
            catch (FileNotFoundException e)
            {
                e.printStackTrace();
                return false;
            }
            
        }
  • 相关阅读:
    No.1
    JS二叉树的操作
    JS实现快排
    BOM中的各种height
    innerHTML outerHTML innerText value 区别
    【转载】JS中DOM操作汇总
    【转载】轻松理解JS闭包
    【转载】JavaScript模块入门
    【转载】JavaScript模块简介
    【转载】浏览器缓存详解:expires cache-control last-modified
  • 原文地址:https://www.cnblogs.com/sallet/p/4250399.html
Copyright © 2020-2023  润新知