Java 过滤所有html标签,复制文件到指定位置
2024-10-18 23:32:52
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;
} }
最新文章
- CSS常见技巧
- iOS,Objective-C,相册功能的实现。
- 李洪强经典iOS面试题11
- Qt一个project调用还有一个project的类成员变量
- 如何通过logcat查看系统程序的意图
- iOS性能调优
- ECSHOP在商品详细页面上获取该商品的顶级分类id和名称
- 玩转12款Linux开源机器人
- 练习使用css3实现3d按钮
- Java中设计模式之工厂模式-4
- 【luogu1220】关路灯
- vue集成百度UEditor富文本编辑器
- 使用MongoDB存储集合的一些问题
- K8S学习笔记之Kubernetes数据持久化方案
- odoo学习之弹框显示
- Github上Laravel开源排行榜Star数前30名
- springboot 单体架构之shiro集成
- day72
- ADO与ADO.Net
- 删除排序数组中的重复数字 II &#183; Remove Duplicates from Sorted Array II
热门文章
- MFC中GetParent()的作用(转)
- 华为上机测试题(MP3光标移动-java)
- This template requires a more recent version of the Android Eclipse plugin. Please update from versi
- Appium+python自动化10-AVD 模拟器【转载】
- 使用dom4j工具包对xml文件解析
- python cProfile分析程序性能
- Centos查看文件夹大小
- Southern African 2001 框架折叠 (拓扑序列的应用)
- Codeforces 1009F	Dominant Indices
- 深入JS正则先行断言