Hello Growler,
Welcome to the forums.
I have some time on my hands so here is a good example to get you going..
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class TxtFiles {
/**
* JavaProgrammingForums.com
*/
// Directory path here
public static String path = ".";
public static void main(String[] args) {
listFiles();
}
public static void listFiles() {
String files;
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
files = listOfFiles[i].getName();
if (files.endsWith(".txt") || files.endsWith(".TXT")) {
// Lists files in console
System.out.println(files);
openFile(files);
}
}
}
}
public static void openFile(String file) {
try {
FileInputStream in = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
// Prints content of file to console
System.out.println(strLine);
// Write file method needs to go here
}
} catch (Exception e) {
System.out.println(e);
}
}
}
This code lists all the .txt files in a directory. It then opens them one by one and displays their content.
You will need to figure out how to write the content to a single file.
All the code you need can be found here -
Java Code Snippets and Tutorials - Java Programming Forums