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
{