import jdk.nashorn.internal.runtime.regexp.joni.Regex;
import java.io.*;
/**
* 把md文档的二级序号转换成代码块
*/
public class mdconvert {
/* 一次读2048byte
String inFile = "D:\\MySQL.md";
FileInputStream inputStream = new FileInputStream(inFile);
BufferedInputStream inputStream = new BufferedInputStream(file);
byte[] bytes = new byte[2048];
int n = -1;
while (( n = inputStream.read(bytes,0,bytes.length)) != -1){
String str = new String(bytes,0,n,"UTF-8");
str = str.replace("->","--");
System.out.println(str);
}
inputStream.close();
*/
public static void main(String[] args){
String inFile = "D:\\MySQL.md";
String outFile = "D:\\MySQL_new.md";
FileInputStream inputStream = null;
InputStreamReader reader = null;
BufferedReader in = null;
BufferedWriter out = null;
try {
inputStream = new FileInputStream(inFile);
reader = new InputStreamReader(inputStream,"UTF-8");
in = new BufferedReader(reader);
File file = new File(outFile);
if (!file.exists()){
file.createNewFile();
}
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile),"UTF-8"));
String str = null;
String strAll = "```mysql\n";
while ((str = in.readLine()) != null ){
while (str.contains(" * SELECT") || str.contains(" - SELECT ")) {
str = str.replaceAll("[-|\\*]\\sSELECT", "SELECT").replaceAll("-[\\s]*>", " -- ").replaceAll("[\\s]+--[\\s]+", " -- ");
strAll += str+"\n";
str = in.readLine();
}
if (!strAll.equals("```mysql\n")){
out.write(strAll);
out.write("\n");
out.write("```\n");
out.write("\n");
strAll = "```mysql\n";
}
out.write(str);
out.write("\n");
}
}catch (FileNotFoundException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}finally {
try {
in.close();
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
[Java]把md文件的二级序号转换成代码块
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...