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"/>

读写文件,用代码在讲html文件转为jsp文件的更多相关文章

  1. PHP文件读写操作之文件写入代码

    在PHP网站开发中,存储数据通常有两种方式,一种以文本文件方式存储,比如txt文件,一种是以数据库方式存储,比如Mysql,相对于数据库存储,文件存储并没有什么优势,但是文件读写操作在基本的PHP开发 ...

  2. php下载文件的代码示例

    php下载文件的代码示例,需要的朋友可以参考下 <?php  $file = 'monkey.gif';  if (file_exists($file)) {  header('Content- ...

  3. C 语言实例 - 输出当前文件执行代码

    C 语言实例 - 输出当前文件执行代码 输出当前文件执行代码,__FILE__ 为当前执行的文件常量. 实例 #include <stdio.h> int main() { FILE *f ...

  4. java:JSP(JSPWeb.xml的配置,动态和静态导入JSP文件,重定项和请求转发,使用JSP实现数据库的增删改查实例)

    1.JSP的配置: <%@ page language="java" import="java.util.*" pageEncoding="UT ...

  5. JSP-Runoob:JSP 文件上传

    ylbtech-JSP-Runoob:JSP 文件上传 1.返回顶部 1. JSP 文件上传 JSP 可以与 HTML form 标签一起使用,来允许用户上传文件到服务器.上传的文件可以是文本文件或图 ...

  6. linux下c通过虚拟地址映射读写文件的代码

    在代码过程中中,把开发过程中比较好的一些代码片段记录起来,如下的代码内容是关于 linux下c通过虚拟地址映射读写文件的代码,应该对小伙伴有些好处.#include<stdio.h>#in ...

  7. huffman压缩解压文件【代码】

    距离上次写完哈夫曼编码已经过去一周了,这一周都在写huffman压缩解压,哎,在很多小错误上浪费了很多时间调bug.其实这个程序的最关键部分不是我自己想的,而是借鉴了某位园友的代码,但是,无论如何,自 ...

  8. Java文件上传细讲

    什么是文件上传? 文件上传就是把用户的信息保存起来. 为什么需要文件上传? 在用户注册的时候,可能需要用户提交照片.那么这张照片就应该要进行保存. 上传组件(工具) 为什么我们要使用上传工具? 为啥我 ...

  9. Java读取文件加锁代码Demo(利用Java的NIO)

    本博文部分转载于:http://blog.csdn.net/wangbaochu/article/details/48546717 Java 提供了文件锁FileLock类,利用这个类可以控制不同程序 ...

随机推荐

  1. XAMPP 下apache部署网站,多个虚拟机(空间)配置

    1.首先修改C盘WINDOWS/system32/drivers/etc目录下的 hosts 文件,用记事本打开,加入: 127.0.0.1 www.a.com 127.0.0.1 www.b.com ...

  2. Spring学习——DI(依赖注入)

    IOC容器,处理对象依赖关系 IOC与DI: IOC :是一个容器,创建对象的容器 DI :在容器创建对象后,处理对象的依赖关系,也叫依赖注入! 方式1:通过set方法注入值 可以给普通属性.集合属性 ...

  3. maven-pom-properties

    出处: http://blog.csdn.net/taiyangdao/article/details/52358083

  4. Linux查找某个时间点后生成的文件(转)

    需要找到某天(例如2017-04-13)以及这之后生成的空文件.那么这个要怎么处理呢?这个当然是用find命令来解决.如下所示, -mtime -5表示查找距现在5*24H内修改过的文件 -type ...

  5. 使用Spring Boot集成FastDFS

    原文:http://www.cnblogs.com/ityouknow/p/8298358.html#3893468 上篇文章介绍了如何使用Spring Boot上传文件,这篇文章我们介绍如何使用Sp ...

  6. 【java】递归统计本地磁盘所有文件,提取重复文件,JDK8 map迭代

    package com.sxd.createDao; import java.io.File; import java.time.LocalDateTime; import java.util.Has ...

  7. 基本的Bootstrap模板

    <!DOCTYPE html> <html> <html lang="zh-cn"> <meta charset="UTF-8& ...

  8. 折腾kubernetes各种问题汇总

    折腾fluend-elasticsearch日志,折腾出一大堆问题,解决这些问题过程中,感觉又了解了不少. 1.如何删除不一致状态下的rc,deployment,service. 在某些情况下,经常发 ...

  9. iOS:地图笔记

    地图笔记 01. CLLocation -------------------------------------------------------- CLLocationManager 定位管理者 ...

  10. IE漏洞调试之CVE-2013-3893

    前言 Windows平台的漏洞挖掘和安全研究中,IE始终是绕不开的话题.IE漏洞就跟adobe系列一样经典,是学习exploit.shellcode的绝佳途径. 在IE漏洞中,UAF即Use-Afte ...