当前位置: 技术问答>java相关
!!!!!!!!!谁能解决这个问题--快快进来--------!!!!!!
来源: 互联网 发布时间:2015-07-12
本文导语: package util; import java.io.*; import java.util.*; import java.text.*; public class LogWriter{ static private LogWriter instance; private Date d = new Date(); DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG,Locale.JAPAN); DateFor...
package util;
import java.io.*;
import java.util.*;
import java.text.*;
public class LogWriter{
static private LogWriter instance;
private Date d = new Date();
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG,Locale.JAPAN);
DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.LONG,Locale.JAPAN);
private FileOutputStream fileOut;
private FileInputStream fileIn;
private PrintWriter pw;
private final String FILE_PATH = "ExceptionLog.log";
static synchronized public LogWriter getInstance(){
if(instance == null){
instance = new LogWriter();
}
return instance;
}
public LogWriter(){
checkFile();
}
public void checkFile(){
File f = new File(FILE_PATH);
if(!f.exists()){
try{
f.createNewFile();
}catch(Exception e){
System.out.print(dateFormat.format(d)+timeFormat.format(d)+"checkFile():"+e.getMessage());
}
}
createLog();
}
public void createLog(){
try{
fileIn = new FileInputStream(FILE_PATH);
BufferedReader br = new BufferedReader(new InputStreamReader(fileIn));
ArrayList sb = new ArrayList();
int i = 0;
while(br.read()!=-1){
sb.add(i,br.readLine());
//System.out.println(br.readLine());
i++;
}
br.close();
fileIn.close();
fileOut = new FileOutputStream(FILE_PATH);
pw = new PrintWriter(fileOut,false);
//StringTokenizer st = new StringTokenizer(new String(sb),"rn");
for(i=0;i
import java.io.*;
import java.util.*;
import java.text.*;
public class LogWriter{
static private LogWriter instance;
private Date d = new Date();
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG,Locale.JAPAN);
DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.LONG,Locale.JAPAN);
private FileOutputStream fileOut;
private FileInputStream fileIn;
private PrintWriter pw;
private final String FILE_PATH = "ExceptionLog.log";
static synchronized public LogWriter getInstance(){
if(instance == null){
instance = new LogWriter();
}
return instance;
}
public LogWriter(){
checkFile();
}
public void checkFile(){
File f = new File(FILE_PATH);
if(!f.exists()){
try{
f.createNewFile();
}catch(Exception e){
System.out.print(dateFormat.format(d)+timeFormat.format(d)+"checkFile():"+e.getMessage());
}
}
createLog();
}
public void createLog(){
try{
fileIn = new FileInputStream(FILE_PATH);
BufferedReader br = new BufferedReader(new InputStreamReader(fileIn));
ArrayList sb = new ArrayList();
int i = 0;
while(br.read()!=-1){
sb.add(i,br.readLine());
//System.out.println(br.readLine());
i++;
}
br.close();
fileIn.close();
fileOut = new FileOutputStream(FILE_PATH);
pw = new PrintWriter(fileOut,false);
//StringTokenizer st = new StringTokenizer(new String(sb),"rn");
for(i=0;i