package reader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Calendar;
import java.util.Vector;
public class LogFileIO {
public LogFileIO(){
}
public String fileNameCheck( String str ) {
String temp = "";
int i = str.length();
temp = str.substring( i-4, i );
return temp;
}
/********logFile에 리스트*********************************************/
public Vector fileList( String directory ){
Vector vec = new Vector();
File myDir = new File( directory );
File[] contents = myDir.listFiles();
for(int i=0; i
String temp = fileNameCheck( contents[i].toString().toLowerCase() );
if( temp.equals( ".txt" )){
vec.add( contents[i].getName() );
}
}
return vec;
}
/*****************************************************************/
/********logFile파일 만들기******************************************/
public void fileWrite( String directory, String str ){
File file = new File( directory + fileName() );
java.io.FileOutputStream writer;
java.io.RandomAccessFile raf = null;
try{
String strLine = "";
raf = new java.io.RandomAccessFile(file, "rw");
raf.seek(raf.length());
writer = new java.io.FileOutputStream(raf.getFD());
strLine = new String( str +"\r\n" );
writer.write(strLine.getBytes());
raf.close();
}catch( Exception e ){
e.printStackTrace();
}
}
/*****************************************************************/
/*******logFile불러오기*********************************************/
public String loadFile( String directory, String filename) {
//Vector vec = new Vector();
StringBuffer buffer = new StringBuffer();
BufferedReader in = null;
//LogfileData logFileData = new LogfileData();
try {
in = new BufferedReader(new FileReader( directory + filename),1024);
String str=null;
while ((str=in.readLine()) != null){
buffer.append( str +"\r\n" );
// LogFile file = logFileData.logFile( str );
// vec.add( file );
}
in.close();
}catch (IOException ie){
System.err.println("File Read Error : "+ie.getMessage());
}
return buffer.toString();
}
/*****************************************************************/
/*******현재 시간 나타내기******************************************/
public String nowTime(){
String temp = "";
Calendar calender;
String year, month, date, hour, minute, sec;
calender = Calendar.getInstance();
calender.get(Calendar.AM_PM);
year = String.valueOf( calender.get(Calendar.YEAR) );
month = String.valueOf( calender.get(Calendar.MONTH) + 1 );
date = String.valueOf( calender.get(Calendar.DATE) );
hour = String.valueOf( calender.get(Calendar.HOUR_OF_DAY) );
minute = String.valueOf( calender.get(Calendar.MINUTE) );
sec = String.valueOf( calender.get(Calendar.SECOND) );
temp = year + "년" + month + "월" + date + "일" + hour + "시" + minute + "분" + sec +"초";
return temp;
}
/*****************************************************************/
public String fileName(){
String temp = "";
Calendar calender;
String year, month, date;
calender = Calendar.getInstance();
year = String.valueOf( calender.get(Calendar.YEAR) );
month = String.valueOf( calender.get(Calendar.MONTH) + 1 );
date = String.valueOf( calender.get(Calendar.DATE) );
temp = year + "년" + month + "월" + date + "일.txt";
return temp;
}
public static void main( String[] args ){
new LogFileIO();
}
}