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;
        }
        
    }

 

posted @ 2015-01-26 15:12  GrandKai  阅读(490)  评论(0编辑  收藏  举报