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();}}}
700字范文,内容丰富有趣,生活中的好帮手!