Created
July 25, 2018 07:42
-
-
Save garywzh/aa57985cd590efcc36b73b9729e1131e to your computer and use it in GitHub Desktop.
软件著作权源代码去空行并复制到一个文件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.File | |
| import java.io.FileNotFoundException | |
| import java.util.* | |
| const val RESULT_PATH = "src/main/resources/result.txt" | |
| const val CODE_PATH = "src/main/resources/javacode" | |
| fun main(args: Array<String>) { | |
| val file = File(CODE_PATH) | |
| File(RESULT_PATH).delete() | |
| listFilesForFolder(file) | |
| } | |
| fun listFilesForFolder(folder: File) { | |
| for (fileEntry in folder.listFiles()!!) { | |
| if (fileEntry.isDirectory) { | |
| listFilesForFolder(fileEntry) | |
| } else { | |
| println(fileEntry.name) | |
| writeToFile(fileEntry) | |
| } | |
| } | |
| } | |
| fun writeToFile(file: File) { | |
| val scanner: Scanner | |
| try { | |
| scanner = Scanner(file) | |
| val result = File("src/main/resources/result.txt") | |
| while (scanner.hasNext()) { | |
| val line = scanner.nextLine() | |
| if (!line.isEmpty()) { | |
| result.appendText(line) | |
| result.appendText("\n") | |
| } | |
| } | |
| scanner.close() | |
| } catch (ex: FileNotFoundException) { | |
| print(ex) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment