- 将文件夹下的所有文件拷贝成
markdown
下的code
public boolean readDirFilesToMarkdown(String filePathDir, String distFileAbsolutePaths) throws Exception {
File file = new File(filePathDir);
File[] files = file.listFiles();
Arrays.sort(files);
StringBuffer stringBuffer = new StringBuffer();
for (File fileItem : files) {
if (fileItem.isFile()) {
InputStreamReader reader = new InputStreamReader(new FileInputStream(fileItem));
BufferedReader br = new BufferedReader(reader);
String line = "";
stringBuffer.append("//" + fileItem.getName() + "\r\n```java\r\n");
boolean flag = false;
while ((line = br.readLine()) != null) {
if (line != null && line.startsWith("package")) {
flag = true;
}
if (flag && line != null) {
stringBuffer.append(line + "\r\n");
}
}
stringBuffer.append("```\r\n");
br.close();
}
}
PrintStream ps = new PrintStream(new FileOutputStream(new File(distFileAbsolutePaths)));
ps.println(stringBuffer.toString());
ps.close();
return true;
}