最近要将一个工程的所有源代码导入到一个文件中,要如下图效果。
于是写了如下代码:最后用Notepad的 NppExport插件 给源代码加上语法高亮,导出为RTF,paste到word中即可。
import java.io.*;
public class ExportCode {
static FileWriter fw;
static BufferedWriter writer;
static String headTitle = "=======================================";
static String endline="\n";
public ExportCode() {}
public ExportCode(String outputPath)
{
String os=System.getProperties().getProperty("os.name");
if(os.startsWith("win")||os.startsWith("Win"))endline="\r\n";
try {
// 设置成尾部追加方式
fw = new FileWriter(outputPath, true);
writer = new BufferedWriter(fw);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @param path 绝对路径
* @param filename 要读的文件名
*/
public void W