import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
public class FileHelper {
public static String readFile(String filename) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader(filename));
String ans = "", line = null;
while((line = reader.readLine()) != null){
ans += line + "rn";
}
reader.close();
return ans;
}
public static void writeFile(String content, String filename) throws Exception {
BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
writer.write(content);
writer.flush();
writer.close();
}
public static void main(String[] args) throws Exception {
String ans = readFile("D:\input.txt");
writeFile(ans, "D:\output.txt");
}
}
import java.util.StringTokenizer;
public class WebpageMaker {
public static String initBegin() {
String s = "<!doctype html><html><head><title></title></head><body>rn";
return s;
}
public static String initEnd() {
String s = "rn</body></html>rn";
return s;
}
public static void createPage(String inputfilename, String outputfilename) throws Exception {
String content = FileHelper.readFile(inputfilename);
StringTokenizer st = new StringTokenizer(content, "rn");
String ans = "";
ans += initBegin();
boolean isCoding = false;
while(st.hasMoreElements()) {
String s = st.nextToken();
int len = s.length();
for(int i=0;i<len;i++) {
if(i+6 <= len && s.substring(i,i+6).equals("<alex>")) {
isCoding = true;
ans += "<pre style="background-color:aliceblue">";
i += 5;
continue;
}
if(i+7 <= len && s.substring(i,i+7).equals("</alex>")) {
isCoding = false;
ans += "</pre>";
i += 6;
continue;
}
char c = s.charAt(i);
if(c == '"') ans += """;
else if(c == '&') ans += "&";
else if(c == '<') ans += "<";
else if(c == '>') ans += ">";
else if(c == ' ') ans += " ";
else if(c == 't') ans += " ";
else ans += c;
}
if(false == isCoding)
ans += "<br />rn";
else
ans += "rn";
}
ans += initEnd();
FileHelper.writeFile(ans, outputfilename);
}
public static void main(String[] args) throws Exception {
createPage("D://test.txt", "D://test.html");
}
}
hello world!
大家好:)
#include
int main() {
printf("hello world!n");
return 0;
}
<!doctype html><html><head><title></title></head><body>
hello world!<br />
大家好:)<br />
<pre style="background-color:aliceblue">#include <stdio.h>
int main() {
printf("hello world!n");
return 0;
}</pre><br />
</body></html>
hello world!
大家好:)
#include <stdio.h>
int main() {
printf("hello world!n");
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有