拿到文件列表
public static void main(String[] args) {
String path = "./"; //要遍历的路径
File file = new File(path); //获取其file对象
try {
f =new FileWriter(new File("./codes.txt")) ;
} catch (IOException e1) {
e1.printStackTrace();
}
func(file);
try {
f.write(codes.toCharArray());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static FileWriter f ;
private static String codes="";
private static void func(File file){
File[] fs = file.listFiles();
for(File f:fs){
if(f.isDirectory()) //若是目录,则递归打印该目录下的文件
func(f);
if(f.isFile()) //若是文件,直接打印
//System.out.println(f);
codes+=f;
}
}
读取文件列表,生成md文件
FileReader input=new FileReader( "./codes.txt" );
BufferedReader br=new BufferedReader(input );
FileWriter output=new FileWriter("./temp.md");
BufferedWriter bw=new BufferedWriter(output);
String s=br.readLine();
while(StringUtils.isNoneEmpty(s)) {
StringBuilder content=new StringBuilder();
content.append("## ");
content.append(s);
content.append("\n");
String[] strArray = s.split("\\.");
int suffixIndex = strArray.length -1;
String ext=strArray[suffixIndex];
content.append("```");
if(ext.equals("vue")) {
content.append("html");
}else {
content.append(ext);
}
content.append("\n");
content.append(FileUtils.readFileToString(new File(s),"UTF-8"));
content.append("\n```\n");
bw.write(content.toString());
s=br.readLine();
}