Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- public class Main {
- public static void main(String[] args) {
- try {
- printFnames("C:\\Users\\Евгений\\Desktop\\Projects\\junit5-master\\junit-platform-runner\\src\\main\\java\\org\\junit\\platform\\runner");
- } catch (Exception ex) {
- System.out.println(ex.getMessage());
- }
- }
- public static void printFnames(String sDir) throws Exception {
- File[] faFiles = new File(sDir).listFiles();
- for (File file : faFiles) {
- if (file.getName().matches(".*\\.java")) {
- char[] data = new char[(int)file.length()];
- new FileReader(file.getAbsolutePath())
- .read(data, 0, data.length);
- String code = getStringFromCharArray(data);
- FileWriter writer = new FileWriter(file.getAbsolutePath());
- writer.write(code.trim().replaceAll(" +", " "));
- System.out.println(file.getAbsolutePath());
- writer.close();
- }
- if (file.isDirectory()) {
- printFnames(file.getAbsolutePath());
- }
- }
- }
- public static String getStringFromCharArray(char[] array) {
- String result = "";
- for (int i = 0; i < array.length; i++)
- result += array[i];
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement