软著整理代码快速生成
程序员文章站
2022-03-05 15:09:51
package com.demo;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.Writer;/** * @author lisa * @date 2020/11/20 - 20:42 */ /** * 申请软著代码复...
package com.demo;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.Writer;
/**
* @author lisa
* @date 2020/11/20 - 20:42
*/
/**
* 申请软著代码复制删除注释和空行
*/
public class SourceExport {
public static void main(String[] args) throws Exception {
//文件读取路径
// File dir = new File("E:\\competition\\miniprogram-34\\miniprogram-34\\pages\\index");
// 1 File dir = new File("E:\\competition\\miniprogram-34\\miniprogram-34\\pages\\main");
// File dir = new File("E:\\competition\\miniprogram-34\\miniprogram-34\\pages\\collection");
// 2 File dir = new File("E:\\competition\\miniprogram-34\\miniprogram-34\\pages\\creativity");
// File dir = new File("E:\\competition\\miniprogram-34\\miniprogram-34\\pages\\main_04");
// 3 File dir = new File("E:\\competition\\miniprogram-34\\miniprogram-34\\pages\\main_04_pages_01");
// 4 File dir = new File("E:\\competition\\miniprogram-34\\miniprogram-34\\pages\\creativity\\chuangyishangpingdetail\\chuangyidetail01");
// 5 File dir = new File("E:\\competition\\miniprogram-34\\miniprogram-34\\pages\\main_02");
// 6 File dir = new File("E:\\competition\\miniprogram-34\\miniprogram-34\\pages\\main_08");
// 7 File dir = new File("E:\\competition\\miniprogram-34\\miniprogram-34\\pages\\myadd");
// 8 File dir = new File("E:\\competition\\miniprogram-34\\miniprogram-34\\pages\\feedback");
File dir = new File("E:\\competition\\miniprogram-34\\miniprogram-34\\pages\\feedback");
// File dir = new File("C:\\Users\\Administrator\\Desktop\\aaa\\src");
//文件输出路径
// File target = new File("C:\\Users\\Administrator\\Desktop\\aaa\\dst\\dst.txt");
File target = new File("E:\\code\\feedback.txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(target));
StringBuffer sb = new StringBuffer();
loopRead(dir, sb);
write(sb.toString(), bw);
}
// 遍历文件夹下所有文件
private static void loopRead(File dir, StringBuffer sb) {
File[] files = dir.listFiles();
if (files != null)
for (File file : files) {
if (file.isDirectory()) {
loopRead(file, sb);
} else {
if (file.length() != 0) {
sb.append(readFileToString(file));
}
}
}
}
//读取文件里面的内容
private static String readFileToString(File file) {
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
try {
br = new BufferedReader(new FileReader(file));
String line = null;
while ((line = br.readLine()) != null) {
String s = line.trim();
if (s.length() == 0) {
continue;
}
if (s.startsWith("/") || s.startsWith("*")) {
continue;
}
sb.append(line).append("\n");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (br != null) {
br.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return sb.toString();
}
//将读取的路径以及相应的内容写入指定的文件
private static void write(String str, Writer writer) {
try {
writer.write(str);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (writer != null)
writer.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
本文地址:https://blog.csdn.net/qq_43525481/article/details/109904205
上一篇: SharedPreferences的进化版-MMKV
下一篇: 手机端常规测试
推荐阅读
-
从零开始学YII2框架(五)快速生成代码工具 Gii 的使用
-
动软代码生成器基础使用
-
【基于EF Core的Code First模式的DotNetCore快速开发框架】完成对DB First代码生成的支持
-
使用代码生成工具Database2Sharp快速生成工作流模块控制器和视图代码
-
java 快速开发框架平台 二次开发 代码生成器 springmvc SSM后台框架源码
-
vs code怎么快速生成html代码?
-
php生成随机密码自定义函数代码(简单快速)
-
.net快速开发平台搭建实例,工作流、代码生成、移动app等
-
java SSM框架 代码生成器 快速开发平台 websocket即时通讯 shiro redis
-
支持网页快速排版 CSS代码一键生成的在线设计工具