import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
public class FileIO{
public static int flag = 0;
public static ArrayList arrFilelist = new ArrayList();
public static void saveToFile(ArrayList arrFilelist) throws IOException {
// TODO code application logic here
FileWriter writer = new FileWriter("D:\\BaseController.csv");
writer.append("Number"+","+"PATH"+","+"Inheretence\n");
try {
for (int i = 0; i < arrFilelist.size(); i++) {
writer.append((i+1)+(String)arrFilelist.get(i));
writer.append('\n');
System.out.println("파일쓰기 완료 : " + (i+1));
}
writer.flush();
} catch (IOException e) {
e.printStackTrace();
} finally{
writer.close();
}
}
public static int checkMatching(String location, String filename)
throws IOException {
// Open BufferReader with given filename
// BufferedReader reader = new BufferedReader(new FileReader(location + "" + filename));
BufferedReader reader = new BufferedReader(new FileReader(location + "\\" + filename));
String line = null;
int count = 0;
try {
flag = 0;
// Loop per every line
while ((line = reader.readLine()) != null) {
// Search the string ex)
// line.matches(".*extends BaseController.*")
if (line.matches(".*extends BaseController.*")) {
count++;
System.out.println(count);
flag = 1;
} else {
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// Close BufferReader
reader.close();
}
return count;
}
public static void FileList(String location) throws IOException {
File file = new File(location);
System.out.println("Location:>" + location + "<");
// Get list of files
File[] fileList = file.listFiles();
// Filelist is null, it will stop.
if (file.listFiles() == null) {
System.out.println("Stop searching : filelist is null");
return;
}
try {
// Loop file list
System.out.println("\tFilelist Loop starting...");
for (int i = 0; i < fileList.length; i++) {
String filename = fileList[i].getName();
System.out.println("\t\tchecking file : [" + filename + "]");
if (fileList[i].isFile()) {
// Save file list into Array(ArrayList, HashMap, .... List )
System.out.println("\t\tFound a file : [" + location + "\\"+ filename + "]");
if(filename.matches(".*Controller.*")){
int count = FileIO.checkMatching(location + "\\", filename);
if(count>=0){
arrFilelist.add("," + location + "\\" + filename + "," + count);
System.out.println(arrFilelist);
}
}
} else if (fileList[i].isDirectory()) {
System.out.println("\t\tFound a directory : [" + filename + "]");
if (!filename.equals(".svn")) {
FileList(location + "\\" + filename);
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// Close File I/O
}
FileIO.saveToFile(arrFilelist);
//System.out.println("File override");
}
public static void main(String[] args) throws IOException {
// Open File I/O
String location = "C:\\BitOss\\Workspace\\OSS_PNA_WFM\\src\\main\\java\\com\\kt\\oss";
// Get list of file in certain(given) directory, Get filename
FileIO.FileList(location);
ExceptionChecking chk = new ExceptionChecking();
if (flag == 1) {
System.out.println("BaseController를 포함하는 파일입니다.\n");
}
}
}
'Study' 카테고리의 다른 글
VMSTAT, SAR, MPSTAT, iostat 명령어를 이용한 서버 모니터링 (0) | 2014.07.09 |
---|---|
[LINUX] OS bit 수 확인 방법, ulimit (0) | 2014.07.09 |
Springframework (0) | 2012.11.28 |
Luke - 3 (0) | 2012.10.05 |
Lucene - 2 (0) | 2012.10.05 |