java ppt 转html5_编写程序,将一个Java文件转换为HTML一个文件

展开全部

java中将java文件62616964757a686964616fe59b9ee7ad9431333337623432转换为html一个文件,先使用file类读取java文件,然后使用string进行分割、替换等操作,输出html后缀名的文件,如下代码:import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileWriter;

import java.io.IOException;

import java.io.InputStreamReader;

public class Change {

String textHtml = "";

String color = "#00688B";

//读取文件

public void ReadFile(String filePath) {

BufferedReader bu = null;

InputStreamReader in = null;

try {

File file = new File(filePath);

if (file.isFile() && file.exists()) {

in = new InputStreamReader(new FileInputStream(file));

bu = new BufferedReader(in);

String lineText = null;

textHtml = "

";

while ((lineText = bu.readLine()) != null) {

lineText = changeToHtml(lineText);

lineText += "";

textHtml += lineText;

}

textHtml += "";

} else {

System.out.println("文件不存在");

}

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

bu.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

//输出文件

public void writerFile(String writepath) {

File file = new File(writepath);

BufferedWriter output = null;

try {

output = new BufferedWriter(new FileWriter(file));

System.out.println(textHtml);

output.write(textHtml);

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

output.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

//文件转换

public String changeToHtml(String text) {

text = text.replace("&", "&");

text = text.replace(" ", " ");

text = text.replace("

text = text.replace(">", ">");

text = text.replace("\"", """);

text = text.replace(" ", "    ");

text = text.replace("public", "public");

text = text.replace("class", "class");

text = text.replace("static", "static");

text = text.replace("void", "void");

String t = text.replace("//", "//");

if (!text.equals(t)) {

System.out.println("t:"+t);

text = t + "";

}

return text;

}

public static void main(String[] args) {

System.out.println("第一个参数为读取文件路径,第二个参数为生成文件路径");

if(args.length<1){

System.out.println("请输入文件路径");

return ;

}else if(args.length<2){

System.out.println("请输入生成文件");

return;

}

Change c = new Change();

c.ReadFile(args[0]);

c.writerFile(args[1]);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值