导出代码
import cn.hutool.core.io.FileUtil;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.Writer;
public class SourceExport {
public static void main(String[] args) throws Exception {
File dir = new File("D:\\filestorage\\src");
File target = new File("C:\\Users\\z\\Desktop\\filestorage_source.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) {
System.out.println(file.getName());
if (file.isDirectory() && !file.getName().equals("test")) {
loopRead(file, sb);
} else {
if (file.length() != 0 && !FileUtil.extName(file).equals("xlsx") && !FileUtil.extName(file).equals("yml")) {
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();
}
}
}
}
删除首位空格
然后再使用notepad++的删除首位空格
word字体宋体,5号
显示行号
一页50行
添加眉页
宋体,小五
导出为pdf即可