读写文件,用代码在讲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"/>
读写文件,用代码在讲html文件转为jsp文件的更多相关文章
- PHP文件读写操作之文件写入代码
在PHP网站开发中,存储数据通常有两种方式,一种以文本文件方式存储,比如txt文件,一种是以数据库方式存储,比如Mysql,相对于数据库存储,文件存储并没有什么优势,但是文件读写操作在基本的PHP开发 ...
- php下载文件的代码示例
php下载文件的代码示例,需要的朋友可以参考下 <?php $file = 'monkey.gif'; if (file_exists($file)) { header('Content- ...
- C 语言实例 - 输出当前文件执行代码
C 语言实例 - 输出当前文件执行代码 输出当前文件执行代码,__FILE__ 为当前执行的文件常量. 实例 #include <stdio.h> int main() { FILE *f ...
- java:JSP(JSPWeb.xml的配置,动态和静态导入JSP文件,重定项和请求转发,使用JSP实现数据库的增删改查实例)
1.JSP的配置: <%@ page language="java" import="java.util.*" pageEncoding="UT ...
- JSP-Runoob:JSP 文件上传
ylbtech-JSP-Runoob:JSP 文件上传 1.返回顶部 1. JSP 文件上传 JSP 可以与 HTML form 标签一起使用,来允许用户上传文件到服务器.上传的文件可以是文本文件或图 ...
- linux下c通过虚拟地址映射读写文件的代码
在代码过程中中,把开发过程中比较好的一些代码片段记录起来,如下的代码内容是关于 linux下c通过虚拟地址映射读写文件的代码,应该对小伙伴有些好处.#include<stdio.h>#in ...
- huffman压缩解压文件【代码】
距离上次写完哈夫曼编码已经过去一周了,这一周都在写huffman压缩解压,哎,在很多小错误上浪费了很多时间调bug.其实这个程序的最关键部分不是我自己想的,而是借鉴了某位园友的代码,但是,无论如何,自 ...
- Java文件上传细讲
什么是文件上传? 文件上传就是把用户的信息保存起来. 为什么需要文件上传? 在用户注册的时候,可能需要用户提交照片.那么这张照片就应该要进行保存. 上传组件(工具) 为什么我们要使用上传工具? 为啥我 ...
- Java读取文件加锁代码Demo(利用Java的NIO)
本博文部分转载于:http://blog.csdn.net/wangbaochu/article/details/48546717 Java 提供了文件锁FileLock类,利用这个类可以控制不同程序 ...
随机推荐
- iOS应用程序多语言本地化
多语言在应用程序中一般有两种做法:一.程序中提供给用户自己选择的机会:二.根据当前用户当前移动设备的语言自动将我们的app切换对应语言. 第一种做法比较简单完全靠自己的发挥了,这里主要讲第二种做法,主 ...
- 如何设断点????-----使用WinDbg调试SQL Server查询
http://www.cnblogs.com/woodytu/p/4665427.html http://www.sqlservercentral.com/blogs/aschenbrenner/20 ...
- 【开源类库学习】MBProgressHUD(提示框)
新博客: http://www.liuchendi.com MBProgressHUD是一个开源类库,实现了各种样式的提示框, 下载地址:https://github.com/jdg/MBProgre ...
- 【java JVM】JVM中类的加载,加载class文件的原理机制
暂时贴图一张,以后补充 解释: 1.符号引用替换为直接引用[参考:http://blog.csdn.net/maerdym/article/details/8087620] 在java中,一个java ...
- 从C转到JAVA学习路之struct与class对比(转)
转自:http://blog.csdn.net/andywxf01/article/details/53506549 JAVA里最牛B的最基本的就是类,而C语言中的struct也可以定义自己的数据结构 ...
- bootstrap popover 如何在hover状态移动到弹出上不消失
bootstrap中的popover其实就是对tooltip做了一定升级,拥有了标题和内容 概要 使用的时候依赖第三方插件 依赖tooltip插件 必须初始化 title 和 content 可以在p ...
- 微信小程序 - 多地点标识(map)
演示如下: wxml <map id="map" scale="{{scale}}" controls="{{controls}}" ...
- Cocos2d-x 3.0中 物理碰撞检測中onContactBegin回调函数不响应问题
好吧,事实上这篇也是暂时冒出来的,近期朋友要做个物理游戏,曾经做物理还是用box2d,呃.确实要花些功夫才干搞懂当中的精髓,可是听讲这套引擎又一次封装了一次.要easy非常多,所以就简单尝试了一下,感 ...
- lodash 判断相等 eq isEqual
var object = { 'a': 1 }; var other = { 'a': 1 }; //true console.log(_.eq(object, object)) //true con ...
- vue sync用法
1.父组件 <add-rule :show.sync="showEditDialog" :addOrUpdate="addOrUpdate" @close ...