File logDir = new File("path/to/log/files");
File[] nonGzippedFiles = logDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return !pathname.getName().contains("gz");
}
});
FileOutputStream combinedLogFiles = new FileOutputStream(new File("path/to/combined.log"));
for (File nonGzippedFile : nonGzippedFiles) {
FileInputStream fileInputStream = new FileInputStream(nonGzippedFile);
int read = 0;
byte[] buff = new byte[128];
while ((read = fileInputStream.read(buff)) > 0) {
combinedLogFiles.write(buff, 0, read);
}
fileInputStream.close();
}
combinedLogFiles.close();
// path/to/combined.log now contains all the contents of the log files
例外処理を行う必要があります。また、これはすでにgzipされたログを行いません。私はその部分を仮定しました
[this](https://codereview.stackexchange.com/questions/77583/copying-contents-of-two-files-into-one-file-bufferedreader-close-コール)? –