Monday, October 3, 2011

File concatenate

i had to concatenate thousands of files which are included in sub directories. after that gooled and collect some java codes , i coded as bellow.

in here ,All files concat to concat.txt file

import java.io.*;

public class ConcatenatedFiles {
public static PrintWriter pw;

static public void main(String arg[]) throws java.io.IOException {
pw = new PrintWriter(new FileOutputStream("C:/concat.txt")); // out fut file name and location
recuriceFiles("G:/smslist/"); // folder which is include all file for concatenate
pw.close();
System.out.println("All files have been concatenated into concat.txt");
}

static void recuriceFiles(String folderName) throws java.io.IOException
{
if(! new File(folderName).isFile())
{
File file = new File(folderName);
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
if(! new File(""+files[i].getPath()).isFile()){
recuriceFiles(files[i].getPath());
}else {
concatFile(files[i]);
}

}

}else{

}
}


static void concatFile(File filename) throws java.io.IOException{
BufferedReader br = new BufferedReader(new FileReader(filename.getPath()));
String line = br.readLine();
while (line != null) {
pw.println(line);
line = br.readLine();
}
br.close();

}
}

  To configure Nginx for a Laravel application located within a subfolder, a  location  block is required to handle requests to that specifi...