JAVA工具类--------(个人)
来源:互联网 发布:下载一亩田软件 编辑:程序博客网 时间:2024/04/30 15:35
package com.aochuang.lotterynews.utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import com.aochuang.lotterynews.core.ResourceLocale;
/**
*
* @author luojiawen
* @version 1.0, 2011.08.25
*/
public class HelpUtil {
public static final String DATEFORMAT = "yyyy-MM-dd HH:mm:ss";
private static final Logger log = LogManager.getLogger(ResourceLocale.class);
//时间格式转换
public static String timeTostring(){
String datetostring =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date());
return datetostring;
}
//时间格式转换
public static String timeTostring(Date date){
String datetostring =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
return datetostring;
}
//时间格式转换
public static String timeTostringYMD(){
String datetostring =
new SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date());
return datetostring;
}
public static String timeTospace(){
String datetostring =
new SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date());
return datetostring;
}
//时间转换成data类型
public static Date getDate(String dateStr){
SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT);
Date rel=null;
try
{
rel = dateFormat.parse(dateStr);
} catch (ParseException e)
{
log.error(e);
}
return rel;
}
//读取TXT文件
public static String getTxtInfo(String filePath) {
String relstr="";
try {
String encoding = "UTF-8"; // 字符编码
File file = new File(filePath);
if (file.isFile() && file.exists()) {
InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);
BufferedReader bufferedReader = new BufferedReader(read);
String lineTXT = null;
while ((lineTXT = bufferedReader.readLine()) != null) {
relstr+=lineTXT;
}
read.close();
} else {
log.error("找不到指定的文件!");
}
} catch (Exception e) {
log.error("读取文件内容操作出错"+e);
}
return relstr;
}
public static boolean isNotNull(Object o){
boolean rel=false;
if(null!=o && !"".equals(o)){
rel=true;
}
return rel;
}
//跟新文件
public static void updateFile(String filePath,String str){
File ss = new File(filePath);
ss.deleteOnExit();
FileOutputStream out1;
try
{
out1 = new FileOutputStream(filePath, false);
BufferedOutputStream out2 = new BufferedOutputStream(out1, 2); // 装饰一个带缓冲输出流
DataOutputStream out = new DataOutputStream(out2); // 装饰一个文件输出流
// out.writeBytes(str);
out.write(str.getBytes("UTF-8"));
out2.close();
out1.close();
} catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
- JAVA工具类--------(个人)
- Java高级个人笔记(RandomStringUtils工具类)
- Java高级个人笔记(StringUtils工具类用法)
- Java时间工具类——DateTime 个人整理
- Java学习个人备忘录之数组工具类
- 个人封装的工具类
- activiti个人写的工具类(SpringMVC)
- activiti个人写的工具类(SpringMVC)
- JAVA操作图片裁切与缩放的一个工具类,个人收藏使用
- Java高级个人笔记(NumberUtils、ArrayUtils和RandomUtils工具类用法)
- C\C++ 程序员从零开始学习Android - 个人学习笔记(三) - java基础 - 环境和工具
- 怎样开始用selenium进行自动化测试(个人总结) 测试工具 java
- 个人一直使用的C#工具类
- 个人搜集的工具类使用指导
- 个人测试用的python工具类
- 个人任务管理工具(TODO工具)
- (个人摘要)make工具的用法
- web 开发工具的选择(个人)
- hive.cli.print.header参数介绍
- continue和break的用法
- 立体化监控
- Chrome单页面最大下载数量限制
- Eclipse导入《Google Android开发入门与实战》一书中豆瓣网客户端例子时候报错
- JAVA工具类--------(个人)
- Java两个整形数组的对比,获取出哪些不同的
- Ubuntu+下构建内核源码树_图文教程
- Android开发错误总结
- Java初级--IO流(上)
- 学到一点
- GCC编译初步 ubuntu c语言入门知识
- CImageList
- [sig09]Rendering Technology at Black Rock Studio