700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > HTML生成器 将txt文件转换为html文件

HTML生成器 将txt文件转换为html文件

时间:2022-10-31 08:06:42

相关推荐

HTML生成器 将txt文件转换为html文件

package HTML文本生成器;import java.io.*;import java.util.Scanner;public class Text_translate {public static void main(String args[]){System.out.println("请需要输入转换文件的地址以及文件名,以及生成html文件地址");Scanner sc=new Scanner(System.in);String addr=sc.next();String name=sc.next();String ta=sc.next();txtToHtml(addr,name,ta);System.out.println("转换成功....");}public static void txtToHtml(String path,String name, String target) {try {String filePath=path+"\\"+name+".txt";String htmlPosition=target+"\\"+name+".html";String encoding = "GBK";File file = new File(filePath);if (file.isFile() && file.exists()) { // 判断文件是否存在InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);// 考虑到编码格式BufferedReader bufferedReader = new BufferedReader(read);// 写文件FileOutputStream fos = new FileOutputStream(new File(htmlPosition));OutputStreamWriter osw = new OutputStreamWriter(fos, "GBK");BufferedWriter bw = new BufferedWriter(osw);String lineTxt = null;while ((lineTxt = bufferedReader.readLine()) != null) {bw.write(lineTxt + "</br>");}bw.close();osw.close();fos.close();read.close();} else {System.out.println("找不到指定的文件");}} catch (Exception e) {System.out.println("读取文件内容出错");e.printStackTrace();}}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。