设为首页 加入收藏

TOP

开发中日常操作转化工具类(五)
2014-11-24 12:02:24 】 浏览:1921
Tags:开发 日常 操作 转化 工具
on();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
return newName;
}
/**
* 把数组转换成字符串,并以逗号分隔
*
* @param arr
* arr
* @return 转换结果
*/
public static String arrayToString(String[] arr)
{
if (arr == null)
{
return "";
}
StringBuffer buf = new StringBuffer();
for (String str : arr)
{
if (str != null && !"".equals(str))
{
buf.append(str).append(',');
}
}
String result = buf.toString();
result = result.replaceAll(",$", "");
return result;
}
/**
* 写Excel
*
* @param response
* response
* @param file
* file
*/
public static void writeExcel(HttpServletResponse response, File file)
{
if (file != null && file.exists())
{
response.reset();
response.setContentType("application/vnd.ms-excel");
response.addHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"");
InputStream inStream = null;
try
{
inStream = new FileInputStream(file);
int len = inStream.read();
while (len != -1)
{
response.getWriter().write(len);
len = inStream.read();
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
Util.close(inStream);
}
}
}
/**
*
* @param reg
* reg
* @param str
* str
* @return boolean
*/
public static boolean test(String reg, String str)
{
Matcher matcher = Pattern.compile(reg).matcher(str);
return matcher.find();
}
/**
*关闭流
* @param ins void
*/
public static void close(InputStream ins)
{
if (ins != null)
{
try
{
ins.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
/**
* 关闭流
* @param ous void
*/
public static void close(OutputStream ous)
{
if (ous != null)
{
try
{
ous.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
/**
*
* 〈重新组装查询条件〉
* 〈如果查询条件包含"_"就在"_"之前加上转义字符"/"〉
* @param queryCondition 查询条件
* @return String
*/
public static String resetCondition(String queryCondition)
{
char[] temps = queryCondition.toCharArray();
//查询条件
StringBuffer condition = new StringBuffer();
//重新组装查询条件的字符串,如果包"_"就在"_"之前加上转义字符"/"
for (char temp : temps)
{
if ('_' == temp)
{
condition.append('/').append(temp);
}
else
{
首页 上一页 2 3 4 5 6 7 8 下一页 尾页 5/9/9
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇数学运算工具类 下一篇利用JDBC连接取数据并导入到EXCEL..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目