Advertisement
Guest User

LW08

a guest
Apr 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.*;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         try {
  9.             printFnames("C:\\Users\\Евгений\\Desktop\\Projects\\junit5-master\\junit-platform-runner\\src\\main\\java\\org\\junit\\platform\\runner");
  10.         } catch (Exception ex) {
  11.             System.out.println(ex.getMessage());
  12.         }
  13.     }
  14.  
  15.     public static void printFnames(String sDir) throws Exception {
  16.         File[] faFiles = new File(sDir).listFiles();
  17.         for (File file : faFiles) {
  18.             if (file.getName().matches(".*\\.java")) {
  19.                 char[] data = new char[(int)file.length()];
  20.                 new FileReader(file.getAbsolutePath())
  21.                     .read(data, 0, data.length);
  22.  
  23.                 String code = getStringFromCharArray(data);
  24.  
  25.                 FileWriter writer = new FileWriter(file.getAbsolutePath());
  26.                 writer.write(code.trim().replaceAll(" +", " "));
  27.                 System.out.println(file.getAbsolutePath());
  28.                 writer.close();
  29.             }
  30.  
  31.             if (file.isDirectory()) {
  32.                 printFnames(file.getAbsolutePath());
  33.             }
  34.         }
  35.     }
  36.  
  37.     public static String getStringFromCharArray(char[] array) {
  38.         String result = "";
  39.         for (int i = 0; i < array.length; i++)
  40.             result += array[i];
  41.         return result;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement