import java.sql.*;
import java.io.*;
import java.util.*;
import java.net.*;
import java.util.Date;
class LogToFile{
String logStr = new String();
PrintWriter log;
String logFile = new String();
String extFile = new String();
String tmpFile = new String();
int countNum=0;
final int WarningNum=20000;
Date now=null;
int a=1;
public LogToFile(String inLogFile){
tmpFile=inLogFile;
now = new Date();
a=now.getDate();
logFile = "./tmplog/"+inLogFile+(1900+now.getYear())+"-"+(1+now.getMonth())+"-"+now.getDate();
extFile = ".txt";
try {
log = new PrintWriter(new FileWriter(logFile+extFile, true), true);
}
catch (IOException e) {
System.out.println("无法打开日志文件: " + logFile);
}
}
public synchronized void DoLog(String inStr){
now = new Date();
log.println((1900+now.getYear())+"-"+(1+now.getMonth())+"-"+now.getDate() + "-"+now.getHours()+"-"+now.getMinutes()+"-"+now.getSeconds()+"<$>" + inStr.replace('\n','N').replace('\r','R') + "<$>end<$>");
//countNum++;
if (now.getDate()!=a)
{
try {
logFile = "./tmplog/"+tmpFile+(1900+now.getYear())+"-"+(1+now.getMonth())+"-"+now.getDate();
log = new PrintWriter(new FileWriter(logFile+extFile, true), true);
//log = new PrintWriter(new FileWriter(logFile+"_a"+extFile, true), true);
//countNum=0;
a=now.getDate();
}
catch (IOException e) {
System.out.println("无法打开日志文件: " + logFile);
}
}
}
public synchronized PrintWriter GetLog(){
return log;
}
}// 上面是一个写文件的类,下面是用法
LogToFile myLog=new LogToFile("LogFileName");
myLog.DoLog("需要书写的文本");
import java.io.*;
import java.util.*;
import java.net.*;
import java.util.Date;
class LogToFile{
String logStr = new String();
PrintWriter log;
String logFile = new String();
String extFile = new String();
String tmpFile = new String();
int countNum=0;
final int WarningNum=20000;
Date now=null;
int a=1;
public LogToFile(String inLogFile){
tmpFile=inLogFile;
now = new Date();
a=now.getDate();
logFile = "./tmplog/"+inLogFile+(1900+now.getYear())+"-"+(1+now.getMonth())+"-"+now.getDate();
extFile = ".txt";
try {
log = new PrintWriter(new FileWriter(logFile+extFile, true), true);
}
catch (IOException e) {
System.out.println("无法打开日志文件: " + logFile);
}
}
public synchronized void DoLog(String inStr){
now = new Date();
log.println((1900+now.getYear())+"-"+(1+now.getMonth())+"-"+now.getDate() + "-"+now.getHours()+"-"+now.getMinutes()+"-"+now.getSeconds()+"<$>" + inStr.replace('\n','N').replace('\r','R') + "<$>end<$>");
//countNum++;
if (now.getDate()!=a)
{
try {
logFile = "./tmplog/"+tmpFile+(1900+now.getYear())+"-"+(1+now.getMonth())+"-"+now.getDate();
log = new PrintWriter(new FileWriter(logFile+extFile, true), true);
//log = new PrintWriter(new FileWriter(logFile+"_a"+extFile, true), true);
//countNum=0;
a=now.getDate();
}
catch (IOException e) {
System.out.println("无法打开日志文件: " + logFile);
}
}
}
public synchronized PrintWriter GetLog(){
return log;
}
}// 上面是一个写文件的类,下面是用法
LogToFile myLog=new LogToFile("LogFileName");
myLog.DoLog("需要书写的文本");
解决方案 »
- 变量声明为接口类型,有什么好处!!
- 刚学java,一个很简单的String问题
- 初学者 请求帮助
- 在下对于Java正则表达式(Regular Expressions)的量词,总是吃不透。哪位达人能指点一二?
- Java内存空间的问题
- 关于构造函数的问题
- 请指教java调用Oracle存储过程,返回数组型参数,取参数值报错
- 各位大哥,帮我看下,顺便改下,多谢
- 关于RMI问题,不得到答案不罢休,帮帮忙,各路神仙,看在明天9.18的份上
- 谁??可以提供JAVA源程序给我啊
- 为什么用javac不能编译HelloWorld.java?提示说javac不是内部命令!
- 如何用程序设置JTable中某一行被选中?
//
void jButton1_actionPerformed(ActionEvent e) {
String a1;StringBuffer buf=new StringBuffer();
try{
a1=textField1.getText();
buf.append(a1);
}catch(IOException ae)//我在运行的时候这句话不对execption java.io.IOException is never thrown in the corresponding try block
{
System.out.println(ae);
}
byte b[]=buf.toString() .trim().getBytes();
FileOutputStream f1=new FileOutputStream("qmjfile1.txt");
f1.write(b);
f1.close() ;
FileInputStream f2=new FileInputStream("qmjfile1.txt");
FileOutputStream f3=new FileOutputStream("qmjfile2.txt");
int c2;
c2=f2.read();
while (c2!=-1)
{
f3.write(c2);
}
f2.close() ;
f3.close() ;
}