设为首页 加入收藏

TOP

开发中日常操作转化工具类(四)
2014-11-24 12:02:24 】 浏览:1920
Tags:开发 日常 操作 转化 工具
(Exception e)
{
result = 0;
}
return result;
}
/**
* 解析字符
*/
public static String[] getValue(String str)
{
if (str == null)
{
return new String[0];
}
return str.split(",");
}
/**
* 直接向用户返回指定信息
*
* @param response
* response
* @param msg
* void
*/
public static void returnMsg(HttpServletResponse response, String msg)
{
Writer out = null;
try
{
out = response.getWriter();
out.write(msg);
out.close();
}
catch (IOException e)
{
LOG.error(e);
}
}
/**
*
* @param str str
* @param reg reg
* @param newValue newValue
* @return String
*/
public static String replace(String str, String reg, String newValue)
{
if (!isEmpty(str))
{
Matcher matcher = Pattern.compile(reg, Pattern.CASE_INSENSITIVE).matcher(str);
str = matcher.replaceAll(newValue);
}
return str;
}
/**
*
* @param str str
* @param reg reg
* @param newValue newValue
* @param param param
* @return String
*/
public static String replace(String str, String reg, String newValue, int param)
{
if (!isEmpty(str))
{
Matcher matcher = Pattern.compile(reg, param).matcher(str);
str = matcher.replaceAll(newValue);
}
return str;
}
/**
* 〈移除字符串中的js代码
*
* @param str
* str
* @return String
*/
public static String removeScript(String str)
{
if (str == null || "".equals(str))
{
return "";
}
int param = Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL;
Matcher matcher = Pattern.compile("<script>.*", param).matcher(str);
str = matcher.replaceAll("");
return str;
}
/**
* 字符串转成整数
*
* @param str
* 字符
* @return 数字
*/
public static int parseInt(String str)
{
int result = 0;
try
{
result = Integer.parseInt(str);
}
catch (Exception e)
{
result = 0;
}
return result;
}
/**
* 〈文件重命名〉
*
* @param realPath
* 文件绝对路径
* @param newName
* 新文件名
* @return String
*/
public static String rename(String realPath, String newName)
{
File file = new File(realPath);
//包含后缀的文件名
String fileName = file.getName();
//不包含后的文件名
String name = fileName.substring(0, fileName.lastIndexOf('.'));
//带后的新文件名称
newName = fileName.replace(name, newName);
realPath = realPath.replace(fileName, newName);
if (file.exists())
{
try
{
if (!file.renameTo(new File(realPath)))
{
throw new Excepti
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 4/9/9
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇数学运算工具类 下一篇利用JDBC连接取数据并导入到EXCEL..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目