易截截图软件、单文件、免安装、纯绿色、仅160KB

Java 异常处理

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
public class ExceptionDefaultHandler
{
private final static String _relativeExceptionLogPath = "log";
private final static String _defaultExceptionLogFileName = "exception.log";

// private static boolean hasFile = false;

private static void generateDefaultLogFile()
{
String absoluteFilePath = ProjectConfig.getNFSCAbsolutePath() +
File.separator + _relativeExceptionLogPath + File.separator +
_defaultExceptionLogFileName;

File file = new File(absoluteFilePath);
if(!file.exists())
{
try
{
file.createNewFile();
}
catch(IOException EX)
{
System.out.println(EX.toString());
}
}
}

private static void generateLogFile(String fileName)
{
String absoluteFilePath = ProjectConfig.getNFSCAbsolutePath() +
File.separator + _relativeExceptionLogPath + File.separator + fileName;

File file = new File(absoluteFilePath);
if(!file.exists())
{
try
{
file.createNewFile();
}
catch(IOException ex)
{
System.out.println(ex.toString());
}
}
}

public static void handle(Exception ex, String fileName)
{
generateLogFile(fileName);

String absoluteFilePath = ProjectConfig.getNFSCAbsolutePath() +
File.separator + _relativeExceptionLogPath+ File.separator + fileName;

File file = new File(absoluteFilePath);
if(file.canWrite())
{
boolean appendFlag = true;
if(file.length() > 1000000)
{
appendFlag = false;
}
PrintWriter streamWriter = null;
try
{
streamWriter = new PrintWriter(new FileOutputStream(file, appendFlag));
streamWriter.write("----------------------------------------------------------------");
streamWriter.write(DateTimeUtil.getCurrentDateLocalFormatString());
streamWriter.write("---------------------------------------------------


相关文档:

通过ibatis的blob 存储java的hashmap

 这几天测试blob获取和存储的时候,被卡了很久,最后才发现是占用了关键字导致无法获取结果,血的教训啊.
以后起名字要用最恶心的,不要用最方便的了.闲话少说,java的hashmap是不能直接存储到数据库中的.
本地数据库为mysql,里面有blob的类型可供使用.方法也很简单,上代码
数据库建表
CREATE TABLE `test` (
`id` ......

java 多线程 专题

CoreJava多线程
线程的概念:
线程指进程中的一个执行流程,一个进程可以包含多个线程。
每一个进程都独享一块内存空间。每个进程都需要操作系统为其分配独立的内存地址,而同一进程中的多个线程在同一块地址空间工作,他们共享一块内存和资源。
java中有两中方法创建一个多线程类:
1、继承java.lang.Thread类,覆盖T ......

Ubuntu下搭建Java开发环境[引用]

安装与设置JDK
Sun JDK的安装基本上有两种方式:
1. 通过Ubuntu提供的包管理工具进行安装
Ubuntu在其包仓库里都包括有JDK的安装,只要sources.list设置正确,通
过apt-get, aptitude, Synaptic Package
Manager等都能安装,而且相关的设置也容易得多;在Ubuntu的新
发布版本里都带了JDK5.0,和JDK6.0的安装支持,而且 ......

Java XML 的 Util

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
public class DocumentUtil
{
public static Document loadXMLByAbsolutePath(String absoluteFilePath, String logFileName)
{
SAXReader saxReader = new SAXReader();
Document document = null;
try ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号