一个工具类方法

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>&nbsp;&nbsp;");
   str=str.replaceAll(" ","&nbsp;");
   return str;
   }

   public static String Codetohtml(String str) {
    str=str.replaceAll("<br>","/n") ;
    str=str.replaceAll("&nbsp;"," ");
    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;
   }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值