package com.tzsw.hjyweb.pub;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class PubFunction{
public final static String CONTEXTPATH="/hjyweb";
public PubFunction(){
}
public static String[] Object2String(Object[] o){
String[] s=new String[o.length];
for (int i=0;i<o.length;i++){
s[i]=(String)o[i];
}
return s;
}
public static String Null2Space(String s){
return s==null?"":s;
}
public static String getDateStr(String datestr){
String result="";
result=datestr.substring(0,10);
int firstdiv=result.indexOf("-");
int lastdiv=result.lastIndexOf("-");
if (firstdiv<0 || lastdiv<0)
result=datestr;
else{
String year=result.substring(0,firstdiv);
String month=result.substring(firstdiv+1,lastdiv);
String day=result.substring(lastdiv+1);
if (month.startsWith("0")) month=month.substring(1);
if (day.startsWith("0")) day=day.substring(1);
result=year+"年"+month+"月"+day+"日";
}
return result;
}
public static String getDateStr2(String datestr){
if (datestr.length()>=10)
return datestr.substring(0,10);
else
return datestr;
}
public static String Htmltocode(String str) {
str=str.replaceAll("/n","<br> ");
str=str.replaceAll(" "," ");
return str;
}
public static String Codetohtml(String str) {
str=str.replaceAll("<br>","/n") ;
str=str.replaceAll(" "," ");
return str;
}
public String getFileContent(String path)
{
String filecontent = "";
StringBuffer fbf=new StringBuffer();
// String realpath=pageContext.getServletContext().getRealPath(path);
try{
File file = new File(path);
if(file.exists())
{
FileReader fr = new FileReader(file);
BufferedReader br=new BufferedReader(fr);
String line=br.readLine();
while(line!=null)
{
line=br.readLine();
if (line==null)
{
break;
}
else
{
fbf = fbf.append(line);
}
}
filecontent=fbf.toString();
br.close();
fr.close();
}
else
{
filecontent = "发生错误,文件找不到";
}
}
catch(Exception e)
{
e.printStackTrace();
}
return filecontent;
}
}