package A1;
import java.io.*;
public class a4 {
public static void main(String[] args) throws FileNotFoundException {
File file = new File("D:\\idea\\ja");
thow(file);
}
public static void thow(File file) {
if (file.isDirectory()) {
File[] files = file.listFiles();
for (File file1 : files) {
if (file1.isDirectory()) {
thow(file1);
}
if (file1.isFile() && file1.getName().endsWith(".java")) {
try (var a = new FileOutputStream("D:\\java123.java", true); var b = new FileInputStream(file1.getAbsolutePath())) {
b.transferTo(a);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
if (file.isFile() && file.getName().endsWith(".java")) {
try (var a = new FileOutputStream("D:\\java123.java", true); var b = new FileInputStream(file.getAbsolutePath())) {
b.transferTo(a);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}