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. codevs 4163 求逆序对的数目 -树状数组法

    4163 hzwer与逆序对  时间限制: 10 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题目描述 Description hzwer在研究逆序对. 对于数列{a},如果 ...

  2. RxJava 2.x 理解-2

    操作符总结: http://reactivex.io/documentation/operators.html https://github.com/ReactiveX/RxJava/wiki Ope ...

  3. Linux下Shell脚本替换换行符(转)

    说明:过滤换行符确实有点吭,不是那么好弄.处理文本时需要将换行符替换为空格,若使用sed命令会比较麻烦,而使用tr命令非常方便. 输入文本(country.txt) China America Fra ...

  4. HTML5本地缓存localStorage和sessionStorage的操作方法收集

    说明: Web Storage 包含如下两种机制: sessionStorage 为每一个给定的源(given origin)维持一个独立的存储区域,该存储区域在页面会话期间可用(即只要浏览器处于打开 ...

  5. ios-真机调试出错信息

    更新证书错误Code Sign error: Provisioning profile ‘XXXX'can't be found                   在Xcode中当你在更新了你得证书 ...

  6. How to Analyze "Deadlocked Schedulers" Dumps?---WINDBG

    https://blogs.msdn.microsoft.com/karthick_pk/2010/06/22/how-to-analyze-deadlocked-schedulers-dumps/ ...

  7. MythXinWCF通用宿主绿色版V1.1

    更新内容:宿主的唯一编号和名称可以输入符号"."日志文本框增加滚动条,并且总是显示文本末端增加启动方式选择:1.手动启动 2.跟随系统启动 最新下载地址: http://pan.b ...

  8. CSS3:3D转换

    几个突破口:(为了更简洁理解,先忽略兼容) 1.认识3D的坐标系 rotateX()-----------元素绕X轴旋转 rotateY() -----------元素绕Y轴旋转 rotateZ() ...

  9. jquery的confirm插件介绍

    参考:1.http://craftpip.github.io/jquery-confirm/ 2.http://www.bootcdn.cn/jquery-confirm/readme/    3.h ...

  10. Android百度地图(二)结合方向传感器我们自己定位哪里走

    Android百度地图(二)结合方向传感器我们自己定位哪里走 本文代码在http://blog.csdn.net/xyzz609/article/details/51943556的基础上进一步改动.有 ...