• 读写文件,用代码在讲html文件转为jsp文件


    package my.testguava;
    
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    import java.nio.charset.Charset;
    import java.util.List;
    
    import com.google.common.io.ByteProcessor;
    import com.google.common.io.ByteStreams;
    import com.google.common.io.FileWriteMode;
    import com.google.common.io.Files;
    
    public class Mytestguava {
        public static void main2(String[] args) {
            String filepath = "/home/rocky/Develop/maven/study_maven/maven_workSpace/worksApproval/src/main/webapp/WEB-INF/page";
            File files = new File(filepath);
            for(File f:files.listFiles())
            {
                System.out.println(f.getName());
            }
            
        }
    
        public List<String> getCommonsjsp(File f) throws FileNotFoundException, IOException
        {
            
            return Files.readLines(f,Charset.defaultCharset());
        }
        
        public void getAllHtml(String commonjsp,String fileDir,String targetDir) throws IOException
        {
            List<String> commonFile = getCommonsjsp(new File(commonjsp));
            File dir = new File(fileDir);
            File[] files = new File(fileDir).listFiles();
            Files futil = null;
            List<String> result = null;
            RandomAccessFile randomFile = null;
            
            BufferedWriter bw = null;
            FileWriter fw = null;
            for(File f : files)
            {
                if(f.getName().endsWith(".html")||f.getName().endsWith(".HTML"))
                {
                    
                    result = Files.readLines(f, Charset.defaultCharset());
                    result.addAll(0, commonFile);
                    fw = new FileWriter(new File(targetDir)+File.separator+f.getName().substring(0, f.getName().lastIndexOf(".html"))+".jsp");
                    bw = new BufferedWriter(fw);
                    for(String line :result)
                    {
                        bw.write(line);
                        bw.newLine();
                    }
                    
                    bw.flush();
                    fw.close();
                    bw.close();
                }
            }
            
        }
        public static void main(String[] args) throws IOException {
            new Mytestguava().getAllHtml("/home/rocky/Develop/job/jianzhi/xieru/webpage/testpage/common.jsp", "/home/rocky/Develop/job/jianzhi/xieru/webpage/testpage/page",
                    "/home/rocky/Develop/job/jianzhi/xieru/webpage/testpage/dirmy2");
            System.out.println(Charset.defaultCharset());
        }
    }
    

     下面的是commonjsp的内容



    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
        <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    <%
        String nameSpace = request.getContextPath();
    %>
    <%
        String projectPath = request.getScheme() + "://"
    					+ request.getServerName() + ":" + request.getServerPort()
    					+ nameSpace + "/";
    %>
    <c:set value="<%=projectPath %>" var="basePath"/>
    
  • 相关阅读:
    php 有趣的头像拼图
    php基础篇-二维数组排序姐妹篇
    php基础篇-二维数组排序 array_multisort
    php应用篇-百度图片的防盗链
    《留给自己,也留给每一位在青春里迷茫找不到自己的年轻人》 爱你现在的时光——白岩松
    没有什么能一下打垮你,就像没有什么能一下拯救你
    php基础篇-双引号、单引号的区别
    TortoiseSVN Start
    cover-view文案被切割:加全角空格
    canvas不显示,必须设置canvas-id
  • 原文地址:https://www.cnblogs.com/rocky-AGE-24/p/6629182.html
Copyright © 2020-2023  润新知