zoukankan      html  css  js  c++  java
  • 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;
            }
            
        }
  • 相关阅读:
    最长公共子序列(LCS)
    数组分割问题
    Trie树
    BitMap(比特位)
    KMP算法——字符串匹配
    排序算法
    概率问题
    【设计模式】——访问者模式
    【设计模式】——解释器模式
    【设计模式】——享元模式
  • 原文地址:https://www.cnblogs.com/sallet/p/4250399.html
Copyright © 2011-2022 走看看