易截截图软件、单文件、免安装、纯绿色、仅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("---------------------------------------------------


相关文档:

java位运算

Java 定义的位运算(bitwise operators )直接对整数类型的位进行操作,这些整数类型包括long,int,short,char,and byte 。表4-2 列出了位运算:
表4.2 位运算符及其结果
运算符                     &nb ......

JAVA虚拟机字符串池相关(笔记)

 JAVA虚拟机有一个字符串池,对于字符串池的访问可以使用字符串对象的intern()方法,可动态向池中添加对象,它的定义如下:
public native String intern();
这是一个本地方法,在调用这个方法时,JAVA虚拟机首先检查字符串池中是否存在与该字符串对象值相等的对象,如果存在就返回字符串池中的对象的引用,否则就新创建一个 ......

Java 如何取得操作系统的属性

 import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;
public class SystemProperties
{
public static String LINE_SEPARATOR = "line.separator";
public static String FILE_SEPARATOR = "file.separator";
public static String USER_LANGUAGE = "user.language"; ......

Java 线程中记录日志

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
public class ThreadLog
{
private final static String _detailLogFile = "log"+File.separator+"detail";
private static boolean _logFlag = true;
priv ......

Java 数据库的Util

 import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import com.paic.is.dispatch.TMPEntry;
import javapassword ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号